【发布时间】:2010-10-08 07:14:44
【问题描述】:
我有 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 标志。但我不能没有它。
【问题讨论】:
-
您似乎忘记了实际的错误信息? :)
-
:D。是的,忘记了错误。已添加。
标签: c++ linux linker g++ static-libraries