undefined reference to `explain_read' ......没有那个文件或目录

undefined reference to `explain_read' ...... No such file or directory

我需要将 libexplain 添加到我的项目中才能完成某些工作。我安装它并将 header libexplain/read.h 添加到我的代码中,到目前为止一切顺利,编译器没有报告任何错误。但是当我使用 libexplain 提供的函数 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

我进行了很多搜索,但仍然不知道出了什么问题。 ):

您需要 link 您的对象文件 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 可以进一步阐明它。