架构x86\u 64的未定义符号:“\u PyUnicode\u Type”,引用自:使用python\u boost时

2024-07-04 07:50:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我的环境在MacOSX 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

然而,哪个图书馆有它们??如有任何建议,我们将不胜感激


Tags: theinfromincludebindusrlocalnamespace
1条回答
网友
1楼 · 发布于 2024-07-04 07:50:41

它是用python-config ldflags解决的

下面是我最后的gcc命令aiwave是我的Python环境名称

$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配置是2.7,但它不知怎么工作

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

相关问题 更多 >

    热门问题