Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Boost.Python与g++; 我正在编写一个围绕C++函数的包装器,用于Python中。因此,我首先尝试使用Boost.Python作为实验。下面是我要包装的函数:_Python_C++_Boost_Linker Errors_Boost Python - Fatal编程技术网

将Boost.Python与g++; 我正在编写一个围绕C++函数的包装器,用于Python中。因此,我首先尝试使用Boost.Python作为实验。下面是我要包装的函数:

将Boost.Python与g++; 我正在编写一个围绕C++函数的包装器,用于Python中。因此,我首先尝试使用Boost.Python作为实验。下面是我要包装的函数:,python,c++,boost,linker-errors,boost-python,Python,C++,Boost,Linker Errors,Boost Python,您好\u exp.cpp: char const* greet() { return "hello, world!"; } #include <boost/python.hpp> BOOST_PYTHON_MODULE(hello_ext) { using namespace boost::python; def("greet", greet); } 然而,经过一些实验后,我一直被这个错误所困扰 Undefined symbols for architec

您好\u exp.cpp:

char const* greet()
{
   return "hello, world!";
}

#include <boost/python.hpp>

BOOST_PYTHON_MODULE(hello_ext)
{
    using namespace boost::python;
    def("greet", greet);
}
然而,经过一些实验后,我一直被这个错误所困扰

Undefined symbols for architecture x86_64:
  "boost::python::detail::init_module(PyModuleDef&, void (*)())", referenced from:
      _PyInit_hello_ext in hello_ext-476eb2.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [hello_ext.so] Error 1
因此,我通过自制安装了python3,以及boost和boost python。注意,我实际上安装了BoostPython库,但不支持python2,只支持python3


提前谢谢你

经过一些修复和挖掘,问题在于我安装的boostpython库仍然在python2中。所以,要确保你做到了

brew rm boost-python
brew install boost-python --with-python3 --without-python
以获得正确的版本。然后,make文件只是更改

BOOSTLIB = -lboost_python


然后点击make:)

看起来你的python不是64位的。。。。通过执行以下命令查看:$file-L/usr/bin/python@HugoCorr结果表明是这样吗?“Mach-O 64位可执行文件x86_64”对不起,我告诉过您默认python二进制文件的外观,但是您应该在自制的版本上执行命令:$file-L/usr/local/cillar/python3/3.6.1/Frameworks/python.framework/Versions/3.6/lib/libpython3.6.so
BOOSTLIB = -lboost_python
BOOSTLIB = -lboost_python3