编译一组项目,其中引入了openssl/aes.h和openssl/md5.h两个文件导致编译过不了

发现Mac上已经安装了OpenSSL的项目,位于/usr/local/Cellar/openssl/,

mac下对于库文件的寻找在Mac系统的不断升级中,已经与他的原始unix,bsd已经大相径庭。我们通过其xcode-select工具的clang可以可见一斑

执行cpp -v命令后,发现如下:

ignoring nonexistent directory "/usr/include"

ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/local/include"

ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/Library/Frameworks"

#include "..." search starts here:

#include <...> search starts here:

 /usr/local/include

 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.1/include

 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include

 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include

 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks (framework directory)

End of search list.


可以看到最先寻找的是/usr/local/include下是否含有

我们可以在/usr/local/include下建立相应的链接,

ln -s /usr/local/Cellar/openssl/1.0.2r/include /usr/local/include/openssl , 

ln -s /usr/local/Cellar/openssl/1.0.2r/lib /usr/local/lib/openssl


亦或者还有一个最简单的方法,直接在项目文件里建立软连接,既不侵入原来的系统,又可以使项目顺利构建。