将库安装到编译中未包含的路径后,编译失败
Compilation fails after install library into a path not included in compilation
>场景:
在 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
标志传递它来解决此问题
- 基于编译器选项的编译二进制路径
- 良好做法:如何定义用于编译的外部库的路径
- 如何更改 clang 的预编译头文件的路径
- Qt 静态编译无法读取路径
- 只有已知执行路径的模板编译
- 已编译的 protobuf 文件的意外输出路径
- 崇高文本 3 - 在终端中编译并运行 C++ 程序(路径包含空格)
- 使用 glibc 2.7 包含路径编译失败
- 将库安装到编译中未包含的路径后,编译失败
- GCC makefile 编译和语法。如何调用 c 编译器以及包含多个路径
- 如果库的包含路径设置不符合预期,如何引发编译错误
- 编译C++中动态链接库,存在运行路径问题
- Simple_ls.cpp的C++Boost编译错误-未找到对Boost的引用::文件系统::路径::文件名
- 在MacOS上编译一个动态库,库搜索路径指向同一目录(CMake)
- GCC - 多个预编译标头和特定路径
- 在C++中编译时提供库路径的更好方法
- 已编译的应用想要从绝对路径加载 DLL
- Qt 创建者编译错误"找不到 UIC.exe从 msvc 2012 路径"
- 在 mingw 下编译时出现路径查找文件名错误
- G++ libc.so 绝对路径交叉编译错误