c - 简单的 Makefile : undefined reference to symbol 'cos@@GLIBC_2.2.5' 问题

标签 c makefile

我正在尝试使用 Makefile 编译一些测试 C 代码。 main.c 文件包含两个 header :

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

当我执行下面的 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)

我明白了

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

如果我从 main.c 中删除 #include "window.h",以及 Makefile 中对 window.o/h/c 的所有引用,它就可以工作.

我错过了什么?我哪里违规了

target: dependencies
[tab] system command

?

最佳答案

听起来像数学库,libm 需要链接进来。在链接阶段添加-lm

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

关于c - 简单的 Makefile : undefined reference to symbol 'cos@@GLIBC_2.2.5' 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23809404/

相关文章:

linux - autotools 项目中 undefined reference

c++ - 为什么 OpenSSL 会崩溃?

c - 将字节数组从 go 传递到 cgo

c - 错误 LNK2019 : unresolved external symbol, fatal error LNK1120: 1 无法解析的外部

c - 递归函数根据步数给出不同的答案

python - 如何使bash和make install使用虚拟环境

git - 如何在 makefile 中强制使用干净的 git 工作存储库?

python - 如何在 OSX 上使用 Python 编译 OpenCV 3.2.0?

调用(是/否)函数来确定用户是否输入了有效的输入

c++ - 如何在 main() C++ 中调用构造函数?