我已经在我的linux机器(CentOS 6.4)上安装了MPICH(版本3.0.4)来进行一些并行计算。我尝试编译“pmandel.c”(以MPICH安装包作为示例)来使用此命令测试我的MPICH安装:
mpicc pmandel.c -o pmandel.out
但它会返回这些错误:
pmandel.c: In function ‘main’:
pmandel.c:279: warning: passing argument 2 of ‘bind’ from incompatible pointer type
/usr/include/sys/socket.h:115: note: expected ‘const struct sockaddr *’ but argument is of type ‘struct sockaddr_in *’
pmandel.c:282: warning: passing argument 2 of ‘bind’ from incompatible pointer type
/usr/include/sys/socket.h:115: note: expected ‘const struct sockaddr *’ but argument is of type ‘struct sockaddr_in *’
pmandel.c:296: warning: passing argument 2 of ‘getsockname’ from incompatible pointer type
/usr/include/sys/socket.h:119: note: expected ‘struct sockaddr * __restrict__’ but argument is of type ‘struct sockaddr_in *’
/tmp/cclNv8nA.o: In function `exponential_complex':
pmandel.c:(.text+0x2fc2): undefined reference to `exp'
pmandel.c:(.text+0x2fd1): undefined reference to `cos'
pmandel.c:(.text+0x2fe5): undefined reference to `sin'
/tmp/cclNv8nA.o: In function `absolute_complex':
pmandel.c:(.text+0x3330): undefined reference to `sqrt'
collect2: ld returned 1 exit status
并且没有输出。我也试过“mpic ++”,“mpiCC”,mpicxx“......但都无济于事。
我应该怎么做才能纠正这个问题?
答案 0 :(得分:1)
@Spiros是正确的,您需要将-lm添加到您的mpicc。在命令的指定位置也很重要。
“在您编写此选项的命令中,它会有所不同;链接器按照指定的顺序搜索和处理库和目标文件。因此,'foo.o -lz bar.o'搜索库'z'在文件foo.o之后但在bar.o之前。如果bar.o引用'z'中的函数,则可能无法加载这些函数。“
见http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html。
它出现在pmandel.out之后。
mpicc pmandel.c -o pmandel.out -lm
或者,您可以使用mpich示例目录中包含的Makefile,只需键入
即可make pmandel