gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 16:27:35 25 4
gpt4 key购买 nike

有什么问题

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

似乎是使用 log2() 但有什么问题吗?实际上,我将它与 OpenMPI 代码一起使用,但评论这一行可以解决问题。

Full Source ( http://pastie.org/7559178 ) 见第 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

似乎 log2(4) 可以工作,但我不能传入变量?

最佳答案

为了链接libm,您需要添加-lm参数,如本文档; MPI under Linux in the Math Department说:

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

关于c - ld : undefined reference to symbol 'log2@@GLIBC_2.2.5' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16006145/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com