天天看点

Ubuntu Uundefined reference to symbol 'pow@@GLIBC_2.2.5'

今天建了一个工程,make后,报错 /usr/bin/ld: Caculator/Calculator.o: undefined reference to symbol 'pow@@GLIBC_2.2.5'

因为使用了mathematical functions,一开始我是在makefile里添加了-lm,但是仍报错,后来检查发现我用的是gcc,于是我把$(CC)改成g++后不报错了。我的工程本来是在Qt里面建的,今天改成自己写makefile管理,报了这个错,Qt工程创建的makefile是个很好的学习范例,我有些东西是看了Qt创建的makefile然后学来的,真的很好用。

  改完后我看了下cc是啥,确实是gcc

@:~/Documents/InterviewSolution/InterviewSolution$ which cc

/usr/bin/cc

@:~/Documents/InterviewSolution/InterviewSolution$ ls -al /usr/bin/cc

lrwxrwxrwx 1 root root 20 11月  8 19:59 /usr/bin/cc -> /etc/alternatives/cc

@:~/Documents/InterviewSolution/InterviewSolution$ ls -al /etc/alternatives/cc

lrwxrwxrwx 1 root root 12 11月  8 19:59 /etc/alternatives/cc -> /usr/bin/gcc

参考

If your code includes mathematical functions (like exp, cos, etc.), you need to link to the mathematics library libm.so. This is done, just like for serial compiling, by adding -lm to the end of your compile command, that is,

mpicc -o sample sample.c -lm

If you are working with C++ you should not compile using the C compiler, use

g++

instead.

https://stackoverflow.com/questions/30013845/compiling-lib-x86-64-linux-gnu-libm-so-6-error-adding-symbols-dso-missing

有人在动态链接库显示调用时使用到的dlclose函数:undefined reference to symbol 'dlclose@@GLIBC_2.2.5' 在QT工程的.pro文件中添加 LIBS=-ldl。

继续阅读