我正在编译一些源代码,需要我已经构建的其他项目中的一些 dylib。我越来越
ld:未找到架构 x86_64` 的符号
每当我执行
g++ some_code.cpp -I/usr/local/include -o executable_binary
我知道g++
无法找到已编译的 dylibs(安装在/usr/local/include
)因为错误还提到了许多属于 dylib 的特定符号。
我已经尝试过这个:
- 执行中
install_name_tool -id "@/usr/local/lib/requiredlib.dylib" /usr/local/lib/requiredlib.dylib
- Adding
-L/usr/local/lib
到编译选项。
- 将所有 dylib 路径显式添加到编译选项中。
- 尝试添加
DYLD_LIBRARY_PATH
失败是因为 Sierra 出于安全原因不允许设置该变量。
我知道可以添加DYLD_LIBRARY_PATH
但这需要禁用 SIP。如果有更干净的方法来做到这一点,我可以通过“我不想”来做到这一点。
P.S.:我正在尝试编译教程示例郁金香图库 http://tulip.labri.fr/TulipDrupal/.
缺少的符号与我安装的图形库有关。错误信息是:
Undefined symbols for architecture x86_64:
"tlp::saveGraph(tlp::Graph*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, tlp::PluginProgress*)", referenced from:
_main in tutorial001-02ee7e.o
"operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, tlp::Graph const*)", referenced from:
_main in tutorial001-02ee7e.o
ld: symbol(s) not found for architecture x86_64
每当我这样做时ls /usr/local/lib/requiredlib.dylib
Tulip 的所有编译库都在那里。
g++ -v
产生:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
做完之后ls /usr/local/include/tulip/
我得到的名单*.h
我打算使用的库的文件。