2013-04-15 83 views
12

哪些错误与LD:未定义的参考符号“的log 2 @@ GLIBC_2.2.5”

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

看起来似乎使用log2()但什么是错?我使用它的openmpi代码实际上,但是评论此行修复的东西。

Full Sourcehttp://pastie.org/7559178见行40

[[email protected] Assign3]$ mpicc -o cpi cpi.c && mpirun -np 16 cpi 
/usr/bin/ld: /tmp/cca9x4he.o: undefined reference to symbol '[email protected]@GLIBC_2.2.5' 
/usr/bin/ld: note: '[email protected]@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 

好像log2(4)工作,但我不能在一个变量传递?

回答

27

在以链接libm你需要添加-lm说法,因为这个文件; MPI under Linux in the Math Department说:

如果你的代码中包含的数学函数(如EXP,COS等), 您需要链接到数学库libm.so.这样做, 就像串行编制,加入-lm您 编译命令的结束,也就是

mpicc -o样品sample.c文件-lm

+0

谢谢,我知道固定的 –

相关问题