【问题标题】:Issue with simple Makefile: undefined reference to symbol 'cos@@GLIBC_2.2.5'简单 Makefile 的问题:未定义对符号“cos@@GLIBC_2.2.5”的引用
【发布时间】:2014-07-11 15:26:08
【问题描述】:

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

#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

?

【问题讨论】:

    标签: c makefile


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      也尝试使用 c++ 代替 gcc 编译器。 它默认包含这个库。

      【讨论】:

        猜你喜欢
        • 2016-03-12
        • 2014-10-26
        • 1970-01-01
        • 1970-01-01
        • 2018-05-25
        • 2013-04-07
        • 2013-04-21
        • 1970-01-01
        相关资源
        最近更新 更多