ld: undefined reference to symbol 'log2@@GLIBC_2.2.5'

匿名 (未验证) 提交于 2019-12-03 08:35:02

问题:

Whats wrong with

for (level = 1; level <= log2((double)size); level++)                          ^ 

Seems like its from using log2() but whats wrong? I am using it with OpenMPI code actually, but commenting this line fixes things.

Full Source(http://pastie.org/7559178) see line 40

[jiewmeng@JM Assign3]$ mpicc -o cpi cpi.c && mpirun -np 16 cpi /usr/bin/ld: /tmp/cca9x4he.o: undefined reference to symbol 'log2@@GLIBC_2.2.5' /usr/bin/ld: note: 'log2@@GLIBC_2.2.5' is defined in DSO /usr/lib/libm.so.6 so try adding it to the linker command line /usr/lib/libm.so.6: could not read symbols: Invalid operation collect2: error: ld returned 1 exit status 

Seems like log2(4) will work but I cant pass in a variable?

回答1:

In in order to link libm you need to add -lm argument, as this document; MPI under Linux in the Math Department says:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!