我正在尝试以下命令:
gcc -o test test.o -lblas
这给出了错误:
/usr/bin/ld: test.o: undefined reference to symbol 'sqrtf@@GLIBC_2.2.5'
/usr/bin/ld: note: 'sqrtf@@GLIBC_2.2.5' is defined in DSO /lib64/libm.so.6 so try adding it to the linker command line
/lib64/libm.so.6:无法读取符号:无效操作 collect2:错误:ld 返回 1 退出状态
但是,当我在命令末尾添加 -lm 时,会出现一大堆错误消息:
test.o: In function `main':
test.cpp:(.text+0xe9): undefined reference to `std::cout'
test.cpp:(.text+0xee): undefined reference to `std::basic_ostream<char,
std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char,
std::char_traits<char> >&, char const*)'
[...]
collect2: error: ld returned 1 exit status
最佳答案
当我尝试链接其他库时,我也遇到了同样的问题。
这是我的解决方案:
安装libtool;
将库路径添加到LD_LIBRARY_PATH;
我使用root来制作。
我不知道它在我的 Ubuntu 上运行的确切原因。但我认为你可以尝试这些步骤。
关于c++ - 链接器 GCC undefined symbol 引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20560188/