在Mac上,我想构建示例Boost.Python代码。
hello.cpp
我使用命令
然后,我通过以下方式编译了
但是它返回了。
如何修复它?
hello.cpp
#include <boost/python.hpp>
char const* greet()
{
return "hello, world";
}
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
我使用命令
brew install boost-python --with-python3
安装了 Boost.Python
。然后,我通过以下方式编译了
hello.cpp
:g++ -fpic -c -L/usr/local/Cellar/boost/1.67.0_1/lib `python3.6m-config --includes --libs --ldflags` hello.cpp
生成了一个名为hello.o
的文件。通过以下方式生成.so
文件:
g++ -shared -L/usr/lib -L/usr/local/Cellar/boost/1.67.0_1/lib -L/usr/local/Cellar/boost-python3/1.67.0_1/lib/ `python3.6m-config --libs --ldflags` -lboost_python3 -o hello_ext.so hello.o
但是它返回了。
ld: library not found for -lboost_python3
clang: error: linker command failed with exit code 1 (use -v to see invocation)
或者用-v
参数输出更详细的内容。
g++ -shared -L/usr/lib -L/usr/local/Cellar/boost/1.67.0_1/lib -L/usr/local/Cellar/boost-python3/1.67.0_1/lib/ `python3.6m-config --libs --ldflags` -lboost_python3 -o hello_ext.so hello.o -v
Apple LLVM version 9.0.0 (clang-900.0.38)
Target: x86_64-apple-darwin17.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
"/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -lto_library /Library/Developer/CommandLineTools/usr/lib/libLTO.dylib -dynamic -dylib -arch x86_64 -macosx_version_min 10.13.0 -o hello_ext.so -L/usr/lib -L/usr/local/Cellar/boost/1.67.0_1/lib -L/usr/local/Cellar/boost-python3/1.67.0_1/lib/ -L/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/config-3.6m-darwin -lpython3.6m -ldl -framework CoreFoundation -lpython3.6m -ldl -framework CoreFoundation -lboost_python3 hello.o -lc++ -lSystem /Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/lib/darwin/libclang_rt.osx.a
ld: library not found for -lboost_python3
clang: error: linker command failed with exit code 1 (use -v to see invocation)
如何修复它?
-lboost_python37
代替。 - leiyc-lboost_python37
是另一个选项。 - GoingMyWay