2015-09-05 33 views
0

我需要将libexplain包括到我的项目中来完成某些工作。我安装它,并将头文件libexplain/read.h添加到我的代码中,迄今为止这么好,编译器没有报告错误。但是,当我用libexplain提供的功能explain_read()和建设项目,它说:对`explain_read'的未定义引用......没有这样的文件或目录

/tmp/cc7NjAw0.o: In function `xl45_read(int, unsigned char*)': 
connections.cpp:(.text+0x2f): undefined reference to `explain_read' 
collect2: error: ld returned 1 exit status 

和构建脚本是:

#!/bin/bash 

echo > ./stdafx.h 
g++ -O1 -Wall -o ./local_proxy (*.cpp...here is the source file list) -lz -lpthread -lpcap -L/usr/local/lib 

其实当我输入

whereis libexplain 

在终端,我得到

libexplain: /usr/lib/libexplain.so /usr/lib/libexplain.a /usr/include/libexplain 

我做了很多搜索,但仍然不知道发生了什么问题。 ):

+1

尝试在构建脚本的“g ++”行末尾添加“-lexplain”。 – TonyB

+0

谢谢你我的朋友,问题解决了@TonyB – xl45

回答

0

您需要将目标文件与libexplain链接。您可以使用-l<library name>做到这一点,就像这样:

g++ -O1 -Wall -o ./local_proxy *.cpp -lz -lpthread -lpcap -lexplain -L/usr/local/lib 

注意-lexplain标志。对于文件名为libABC.so的库,您可以使用-lABC来引用该库。 documentation for link options with GCC可以揭示更多的光。

+0

建立成功,非常感谢!花了我很多时间,虽然这是一个愚蠢的问题......顺便说一句,我怎么知道某些库的链接参数,说它是'-lexplain' for'libexplain',你怎么知道这个... – xl45

+0

那里,给了一个通用示例和GCC文档的链接。基本上它与你试图链接的动态库的实际名称有关。 – cyphar

相关问题