nak*_*iya 0 c++ linux linker g++ static-libraries
我有3个小文件,用于制作静态库和应用程序:
test.h
#ifndef TEST_H
#define TEST_H
class Test
{
    public:
        Test();
};
extern Test* gpTest;
#endif
TEST.CPP
#include "test.h"
Test::Test()
{
    gpTest = this;
}   
Test test;
main.cpp中
#include "test.h"
#include <iostream>
using namespace std;
Test* gpTest = NULL;
int main()
{
    return 0;
}
建立
g++ -c test.cpp -o test.o
ar cr test.a test.o
g++ -c main.cpp -o main.o
g++ main.o -o app -Wl,--whole-archive -L/home/dumindara/intest/test.a -Wl,-no--whole-archive
错误(链接步骤)
/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status
我尝试了一切:使用-static-libgcc并链接到静态libstdc ++.无法让这个工作.这完全归功于--whole-archive标志.但我离不开它.
我认为这--是问题所在:
-Wl,-no--whole-archive
试试吧
-Wl,-no-whole-archive
编辑
关于没有在你的应用程序中看到测试符号与nm应用程序:我认为你不需要,-L因为你提供完整的路径和test.a的名称 - 做任何一个
-Wl,--whole-archive -L/home/dumindara/intest/ -ltest -Wl,-no-whole-archive
要么
-Wl,--whole-archive /home/dumindara/intest/test.a -Wl,-no-whole-archive