D语言新手问题 macOS 编译提示 ld: library not found for -lssl

· Created · Last modified by Brian replied at · 394 times read

编译错误提示

> dub build                                                                                            master [e297373]
Performing "debug" build using /Library/D/dmd/bin/dmd for x86_64.
hunt 1.4.0: target for configuration "library" is up to date.
hunt-openssl 1.0.1: target for configuration "library" is up to date.
hunt-net 0.4.2: target for configuration "ssl" is up to date.
hunt-sql 1.3.0: target for configuration "library" is up to date.
hunt-database 2.0.0-beta.4: target for configuration "ssl" is up to date.
mysql-demo ~master: building configuration "application"...
Linking...
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: linker exited with status 1
/Library/D/dmd/bin/dmd failed with exit code 1.

看到这个提示很明显是没有安装 openssl 开发包,那就安装一个呗:
brew install openssl

安装后执行编译还是出现这样个错误,应该是链接路径不对,再次添加链接路径到环境变量:
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib

按道理来说到了这个步骤问题就已经解决,再次执行编译,如果还出现问题那就是 macOS 开发工具 xcode 惹的祸。

这个是 macOS 系统设定问题,你必须先安装 xcode 支持,在终端输入命令:
xcode-select --install

提示是否安装后点击【安装】。

要注意的是这个安装过程是从网络下载,所以会稍稍有点慢。

就此来说问题已经完全解决,执行编译:

> dub build                                                                                            master [e297373]
Performing "debug" build using /Library/D/dmd/bin/dmd for x86_64.
hunt 1.4.0: target for configuration "library" is up to date.
hunt-openssl 1.0.1: target for configuration "library" is up to date.
hunt-net 0.4.2: target for configuration "ssl" is up to date.
hunt-sql 1.3.0: target for configuration "library" is up to date.
hunt-database 2.0.0-beta.4: target for configuration "ssl" is up to date.
mysql-demo ~master: building configuration "application"...
Linking...
To force a rebuild of up-to-date targets, run again with --force.

编译成功!

Login to reply