C++ 链接器GCC对符号的未定义引用

C++ 链接器GCC对符号的未定义引用,c++,linker,blas,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/

我正在尝试以下命令:

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
test.o:在函数'main'中:
test.cpp:(.text+0xe9):对“std::cout”的未定义引用

test.cpp:(.text+0xee):未定义对“std::basic_ostream&std::operator”的引用我在尝试链接其他库时遇到了相同的问题

以下是我的解决方案:

  • 安装libtool

  • 将库路径添加到LD_library_path

  • 我用根来做


  • 我不知道它在我的Ubuntu上工作的确切原因。但是,我认为你可以试试这些步骤。

    当构建C++程序时,使用<代码> G++< /COD>而不是<代码> GCC 。在命令行中添加“-LSTDC++”可以帮助。@ JoklevVD:即使约阿希姆链接,也可以应用他的评论。手动添加libstdc++不是正确的方法。谢谢。“我忘了这一点——ups!”小丑:如果你知道自己在做什么,它很容易被覆盖。如果您正在努力理解上述错误的含义,您甚至不应该尝试手动链接。