g++直接链接gcc生成的静态库文件,会出现以下错误:
[search@SY-0187 test]$ g++ test.cpp -o test -L. -lmyhelloc
/tmp/cc83gjbt.o: In function `main':
test.c:(.text+0x5): undefined reference to `hello()'
collect2: ld returned 1 exit status
找不到静态库中的函数,原因是:
c++的函数名的生成和c的函数名的生成不同,在c中只根据函数名和调用约定、c++还要加上参数类型列表,所以c++编译器无法找到函数。 解决 |