简单的Makefile问题:未定义的对符号“cos@@GLIBC_2.2.5”的引用。

时间:2022-06-19 17:44:51

I'm trying to compìle some test C code using a Makefile. The main.c file includes two headers:

我正在尝试用Makefile编译一些测试C代码。主要的。c文件包括两个标题:

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

and when I execute the following Makefile

当我执行下面的Makefile时。

# 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)

I get

我得到

xxx@xxx:~/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 'cos@@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

If I remove #include "window.h" from main.c, and all the references to window.o/h/c in the Makefile, it works.

如果我移除#include“窗口”。从主要h”。以及所有对窗口的引用。在Makefile中,它可以工作。

What am I missing? Where am I breaking the rule

我缺少什么?我在哪里违反规定?

target: dependencies
[tab] system command

?

吗?

2 个解决方案

#1


29  

Sounds like the math library, libm needs to be linked in. Add -lm to the linking stage.

听起来像数学图书馆,libm需要链接进去。将-lm添加到链接阶段。

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

#2


-3  

Also try to use c++ instead of gcc compiler. It includes this library by default.

还可以尝试使用c++而不是gcc编译器。它默认包含这个库。

#1


29  

Sounds like the math library, libm needs to be linked in. Add -lm to the linking stage.

听起来像数学图书馆,libm需要链接进去。将-lm添加到链接阶段。

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

#2


-3  

Also try to use c++ instead of gcc compiler. It includes this library by default.

还可以尝试使用c++而不是gcc编译器。它默认包含这个库。