macpython没有numpy库,ld:在MacOS上找不到-lboost_python的库

On Mac, I want to build the example Boost.Python code

hello.cpp

#include

char const* greet()

{

return "hello, world";

}

BOOST_PYTHON_MODULE(hello_ext)

{

using namespace boost::python;

def("greet", greet);

}

I installed the Boost.Python with brew install boost-python --with-python3

And I compiled the hello.cpp by

g++ -fpic -c -L/usr/local/Cellar/boost/1.67.0_1/lib `python3.6m-config --includes --libs --ldflags` hello.cpp

There is a hello.o file generated. And generate .so file by

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

But it returned

ld: library not found for -lboost_python3

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Or more detailed output with -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)

How can I fix it?

解决方案

Finally, I found there is no such libboost_python37.dylib in boost-python lib path

$ ls /usr/local/Cellar/boost-python3/1.67.0_1/lib

libboost_numpy37-mt.a libboost_numpy37.a libboost_python37-mt.dylib libboost_python37.dylib

libboost_numpy37-mt.dylib libboost_numpy37.dylib libboost_python37-mt.a libboost_python37.a

So I created a soft link

$ sudo ln -s libboost_python37.dylib libboost_python3.dylib

I can compile my code now.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值