0

I have installed MPICH (ver 3.0.4) on my linux machine (CentOS 6.4) for doing some parallel computation. I tried to compile "pmandel.c" (which comes with MPICH installation package as an example) to test my MPICH installation with this command :

mpicc pmandel.c -o pmandel.out

but it returns these errors:

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

and no output is made. I also tried with "mpic++", "mpiCC", mpicxx" ... but all to no avail.

what should I do to correct this?

gnome
  • 573
  • 1
  • 6
  • 19

1 Answers1

1

@Spiros is correct that you need to add -lm to your mpicc. It matters where in the command you specify it, too.

"It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded."

see http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html.

It comes after pmandel.out.

mpicc pmandel.c -o pmandel.out -lm

Alternatively, you can use the Makefile included in the mpich examples directory and just type

make pmandel
kraffenetti
  • 365
  • 1
  • 10
  • 1
    From the GCC page I referenced: "It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded." – kraffenetti Sep 09 '13 at 22:22
  • 1
    I should also note that mpicc is merely a convenience wrapper for an underlying C compiler, which is why the GCC rules apply. – kraffenetti Sep 10 '13 at 14:40
  • Looking at the makefile, it seems that one should not only add `-lm` but also `-lpthread -lmpi` – Urhixidur Jun 17 '15 at 20:27