体系结构的未定义符号 x86_64:“_PyUnicode_Type”,引用自:使用 python_boost 时

Undefined symbols for architecture x86_64: "_PyUnicode_Type", referenced from: when using python_boost

我的环境在 Mac OSX Catalina 上使用 Anaconda/Python 3.7.9。

我已经为 conda boost

安装了 boost_python
#include <boost/python.hpp>

char const * doYouDo( const char* jobs ){
    return "Hello, I am an embedded engineer.";
}

BOOST_PYTHON_MODULE( what ){
    boost::python::def( "doYouDo", doYouDo);
}

然后用这个编译。

g++ -fPIC -Wall -I/Users/whitebear/anaconda3/envs/aiwave/include/boost/python/ -I/Users/whitebear/anaconda3/envs/aiwave/include/python3.7m/ -lboost_python37 -shared -o whatModule.so what.cpp

我在下面收到这个错误。

In file included from what.cpp:1:
In file included from /usr/local/include/boost/python.hpp:28:
In file included from /usr/local/include/boost/python/exception_translator.hpp:10:
/usr/local/include/boost/bind.hpp:36:1: warning: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use
      <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior. [-W#pragma-messages]
BOOST_PRAGMA_MESSAGE(
^
/usr/local/include/boost/config/pragma_message.hpp:24:34: note: expanded from macro 'BOOST_PRAGMA_MESSAGE'
# define BOOST_PRAGMA_MESSAGE(x) _Pragma(BOOST_STRINGIZE(message(x)))
                                 ^
<scratch space>:2:2: note: expanded from here
 message("The practice of declaring the Bind placeholders (_1, _2, ...) " "in the global namespace is deprecated. Please use " "<boost/bind/bind.hpp> + using namespace bo...
 ^
1 warning generated.
Undefined symbols for architecture x86_64:
  "_PyUnicode_Type", referenced from:
      boost::python::to_python_value<char const* const&>::get_pytype() const in what-7927a1.o
  "__Py_NoneStruct", referenced from:
      boost::python::api::object::object() in what-7927a1.o
      boost::python::converter::pointer_arg_from_python<char const*>::pointer_arg_from_python(_object*) in what-7927a1.o
      boost::python::converter::pointer_arg_from_python<char const*>::operator()() const in what-7927a1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我猜它说没有 _PyUnicode_Type,__Py_NoneStruct

但是哪个图书馆有呢??任何建议表示赞赏。

python-config --ldflags

解决了

我最后的 gcc 命令如下。 aiwave 是我的 anacond 环境名称

$export LIBRARY_PATH=/Users/whitebear/anaconda3/envs/aiwave/lib/
$g++ -fPIC -Wall -I/Users/whitebear/anaconda3/envs/aiwave/include/boost/python/ -I/Users/whitebear/anaconda3/envs/aiwave/include/python3.7m/ `python-config --ldflags` -lboost_python37 -shared -o whatModule.so what.cpp

附加信息

我的 python-config 是 2.7,但它以某种方式工作

$python-config --ldflags
-L/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config -lpython2.7 -ldl -framework CoreFoundation