C中的编译问题

时间:2014-10-25 17:15:29

标签: c compilation linker-errors

我编译程序时遇到问题而且我不知道为什么。我认为这是一个图书馆问题,但我不确定。我在谷歌搜索但我无法解决问题。

命令行:

clang `pkg-config --libs opencv `  main.o image_handle.o image_detection.o neural_network.o   -o main

这是我的错误消息:

/usr/bin/ld: neural_network.o: undefined reference to symbol 'exp@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1

编辑:我的Makefile

#For the compilation
CC=clang

CPPFLAGS=`pkg-config --cflags opencv`
CFLAGS= -Wall -Wextra -Werror -std=c99 -O2
LDFLAGS=`pkg-config --libs opencv`

SRC= main.c image_handle.c image_detection.c neural_network.c
OBJ= ${SRC:.c=.o}

all: main clean

main: ${OBJ}

clean:
    rm -f *~ *.o

#END

2 个答案:

答案 0 :(得分:2)

/lib/x86_64-linux-gnu/libm.so.6: error adding symbols:
                                 DSO missing from command line

这是链接器告诉你它找到了它正在寻找的符号,但不是在你要求它链接的库中。因此,您应该将该库添加到命令行。 libm的标记为-lm

clang main.o image_handle.o image_detection.o neural_network.o \
       `pkg-config --libs opencv ` -lm -o main

(您将库放在命令行上需要它们的对象之后。)

答案 1 :(得分:0)

链接时参数的顺序很重要 - 您需要在目标文件之后列出库。尝试:

clang main.o image_handle.o image_detection.o neural_network.o   -o main `pkg-config --libs opencv `