2014-05-22 5 views
17

Ich versuche, einige Test-C-Code mit einem Makefile zu complen. Die main.c-Datei enthält zwei Header:Problem mit einfachem Makefile: undefinierter Verweis auf Symbol 'cos @@ GLIBC_2.2.5'

#include "circle_buffer.h" 
#include "window.h" 

und wenn ich die folgende Makefile ausführen

# compiler 
CC=gcc 

# compiler flags: 
# -g adds debugging information to the executable file 
# -Wall turns on most, but not all, compiler warnings 
CFLAGS= 

# include path 
INCLUDES = 

# library path and names  
LIBS=-L/usr/lib/x86_64-linux-gnu -lsndfile 

MAIN = test 

$(MAIN): main.o circle_buffer.o window.o 
    $(CC) main.o circle_buffer.o window.o -o $(MAIN) $(LIBS) 

main.o: main.c circle_buffer.h window.h 
    $(CC) -c main.c $(INCLUDES) 

circle_buffer.o: circle_buffer.c circle_buffer.h 
    $(CC) -c circle_buffer.c $(INCLUDES) 

window.o: window.h 
    $(CC) -c window.c $(INCLUDES) 

.PHONY: clean 

clean: 
    rm -rf *o $(MAIN) 

ich

[email protected]:~/source$ make 
gcc -c main.c 
gcc -c circle_buffer.c 
gcc -c window.c 
gcc main.o circle_buffer.o window.o -o test -L/usr/lib/x86_64-linux-gnu -lsndfile 
/usr/bin/ld: window.o: undefined reference to symbol '[email protected]@GLIBC_2.2.5' 
//lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line 
collect2: error: ld returned 1 exit status 
make: *** [test] Error 1 

Wenn ich #include "window.h" von main.c entfernen und alle Verweise auf window.o/h/c im Makefile funktioniert es.

Was fehlt mir? Wo bin ich gegen die Regel

target: dependencies 
[tab] system command 

?

Antwort

29

Klingt, dass die Math-Bibliothek libm verknüpft werden muss. Fügen Sie -lm zur Verknüpfungsstufe hinzu.

LIBS=-L/usr/lib/x86_64-linux-gnu -lsndfile -lm 
-3

Versuchen Sie auch, C++ anstelle von GCC-Compiler zu verwenden. Es enthält standardmäßig diese Bibliothek.

Verwandte Themen