将库安装到编译中未包含的路径后,编译失败

Compilation fails after install library into a path not included in compilation

本文关键字:编译 路径 失败 包含 安装      更新时间:2023-10-16

>场景:

在 Debian 8 上,我安装了 openssl 库(运行时和开发版本),版本 1.0.1t。这些是使用apt-get.因此,默认位置:/usr/include//usr/lib

我编译了一个使用 openssl 库的文件:(从qmake生成)

g++ -c -pipe -O2 -fPIC -std=gnu++11 -Wall -W -DHAVE_OPENSSL -D_REENTRANT -DENABLE_IPV6 -DTIXML_USE_STL -DBOOST_FILESYSTEM_DEPRECATED -DQT_NO_DEBUG -I. -I. -Isrc -Isrc/engine -Isrc/gui -Isrc/gui/qt -Isrc/gui/qt/qttools -Isrc/net -Isrc/engine/local_engine -Isrc/engine/network_engine -Isrc/config -Isrc/core -Isrc/third_party/websocketpp -isystem /usr/include -isystem /usr/include/mysql -isystem /usr/include/mysql++ -I/opt/gsasl/include -I~/Qt/5.9.0_static/mkspecs/linux-g++ -o obj/crypthelper.o src/core/common/crypthelper.cpp

它工作完美。请注意,不包含/usr/local/标题。

目标:

使用 openssl 1.1.1b 执行相同的操作(以重现错误)

我从源代码安装 openssl 1.1.1b(不删除 1.0.1t),它会安装到/usr/local中。
首先,为了确保没有任何变化,我运行相同的命令(它没有引用/usr/local),它抱怨:

In file included from /usr/include/openssl/evp.h:66:0,
from /usr/include/openssl/x509.h:73,
from /usr/include/openssl/ssl.h:156,
from src/core/openssl_wrapper.h:75,
from src/core/common/crypthelper.cpp:34:
/usr/local/include/openssl/opensslconf.h:20:3: error: #error OPENSSL_ALGORITHM_DEFINES no longer supported    <---- WHY???
# error OPENSSL_ALGORITHM_DEFINES no longer supported

为什么它从位于/usr/local的文件抱怨?为什么包括?
没有引用此目录!我不明白。

PD:对不起,标题,没有比这更好的了。请随时更正。

/usr/local/include位于编译器的默认搜索路径中

您可以通过调用echo | g++ -E -v -来检查这些内容

您应该获得类似于以下内容的输出:

...
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/8/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/8/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
...

通过传递-isystem /usr/include,您将/usr/include移动到搜索列表的顶部,并且首先找到openssl 1.0.1中的标题。但是<openssl/opensslconf.h>位于其他地方(对我来说是/usr/include/x86_64-linux-gnu/openssl/opensslconf.h),这是在/usr/local/include之后搜索的,因此首先找到openssl 1.1.1的版本。

您可以通过找到包含正确 opensslconf.h 的目录并修改您的构建以使用-isystem标志传递它来解决此问题