c++ - 链接器 GCC undefined symbol 引用

标签 c++ linker blas

我正在尝试以下命令:

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

最佳答案

当我尝试链接其他库时,我也遇到了同样的问题。

这是我的解决方案:

  1. 安装libtool;

  2. 将库路径添加到LD_LIBRARY_PATH;

  3. 我使用root来制作。

我不知道它在我的 Ubuntu 上运行的确切原因。但我认为你可以尝试这些步骤。

关于c++ - 链接器 GCC undefined symbol 引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20560188/

相关文章:

c++ - 使用数组聚合初始化结构数组

c++ - g++ 表示 : warning: statement has no effect for shift bits operators

c++ - linux下c/c++的加密库和压缩库

c++ - C++ 中的动态链接不起作用

windows - 如何手动创建可执行的 .exe PE 文件?

c - 布拉斯 : Matrix product in C?

c++ - uBLAS 慢速矩阵-稀疏 vector 乘法

javascript - 为什么有些编程语言允许自动包含分号?

linux - 为什么我的代码会在启动函数结束时崩溃?

c - 使用 GNU Blas 子程序在 vector 和矩阵之间进行元素乘积