一个关于gcc编绎一个简单程序的奇怪问题!?
fi9 2003-02-18 11:24:09 昨晚想到去linux下写个动态/静态库,所以就写了下面的两个程序:
// test_library.h
int test(void);
// test_library.cpp
#include <stdio.h>
#include "test_library.h"
int test(void)
{
printf("test library!\n");
return(0);
}
// test.cpp
#include "test_library.h"
int main(int nP, char *cpP)
{
test();
return(0);
}
然后
gcc -c test_library.cpp -o test_library.o
gcc -shared -Wl,soname,libtest.so.1 test_library.o -o libtest.so.1.0
或者
ar cqs test_library.o -o libtest.a
以上都成功地生成动态库和静态库
接着是编绎测试程序test
gcc -c test.cpp -o test.o //成功
gcc test.o -L/current_dir -ltest -o test //出错
出错的大意是:链接错误!找不到函数__gxx_perso???_vol()!
我用nm test.o来查看到以下内容(大概吧)
__gxx_perso???_vol() // 为什么第一个函数就是这个呢?!
// 它又是怎么出来的?!我的程序里没有这个函数啊!
main()
test()