g – 如何从shell中编译在macOS Sierra上使用dylib路径的源代码
我正在编译一些源代码,需要我已经建立的其他项目的一些dylibs.我越来越
每当我执行 g++ some_code.cpp -I/usr/local/include -o executable_binary 我知道g不能找到编译的dylib(安装在/usr/local / include),因为错误还提到了很多特定的符号,这些是dylib的一部分. 我已经尝试过: >执行install_name_tool -id“@ /usr/local / lib / requiredlib.dylib”/usr/local/lib/requiredlib.dylib 我知道可能添加DYLD_LIBRARY_PATH但需要禁用SIP.我可以做到这一点,我不想,如果有一个更干净的方法来做到这一点. P.S .:我正在编译Tulip graph library的教程示例. 缺少的符号与我安装的图形库有关.错误信息是: 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文件的列表.
此外,您还可以查看ld的未定义选项
在编译您的二进制文件时,您将称为-Wl,-undefined,dynamic_lookup. 您还可以使用-lazy-lx或-lazy-library路径,以便在调用库中的第一个函数之前不会加载该库,这在某些情况下可能有所帮助. 然后添加rpath标志,更改名称与install_name_tool像@macmoonshine显示,但请确保指向正确的路径.默认情况下,郁金香安装在默认库文件夹/usr/local中,但建议在安装指南中将其用于用户管理目录. 对于郁金香所需的所有库,类似于以下命令. install_name_tool -change ./build-release/lib/libtulip-core-4.11.dylib '@rpath/libtulip-core-4.11.dylib' tutorial001 并在编译教程时使用-Wl,-rpath,./ build-release / lib. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |