2013-04-15 17 views
12

Was stimmt nicht mitld: undefined reference to Symbol 'log 2 @@ GLIBC_2.2.5'

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

Scheint wie seine verwenden log2() aber was ist falsch? Ich benutze es tatsächlich mit OpenMPI-Code, aber das Kommentieren dieser Zeile behebt die Dinge.

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

Scheint, wie log2(4) funktioniert, aber ich kann nicht in eine Variable übergeben?

Antwort

27

Um zu verknüpfen libm müssen Sie -lm Argument hinzufügen, wie dieses Dokument; MPI under Linux in the Math Department sagt:

Wenn Ihr Code mathematische Funktionen (wie exp, cos, usw.) enthält, Sie auf die Mathematik-Bibliothek libm.so. verknüpfen müssen Dies geschieht wie für die serielle Compilieren von -Im bis zum Ende Ihrer Kompilierungsbefehl hinzufügen, das heißt,

mpicc -o Probe Sample.c -Im

+0

Danke, ich habe repariere das –