【发布时间】:2020-08-08 21:03:11
【问题描述】:
对于安装,我遵循了这个程序 --> boost-py#installation-for-linux-ubuntu
文件:
- 'CMakeLists.txt'
cmake_minimum_required(VERSION 3.0)
find_package(Boost COMPONENTS python36 required)
find_package(PythonInterp 3)
find_package(PythonLibs 3)
PYTHON_ADD_MODULE(hello hello.cpp)
include_directories(/usr/include/python3.6m)
FILE(COPY hello.py DESTINATION .)
add_test(NAME 01-HelloWorld COMMAND ${PYTHON_EXECUTABLE} hello.py)
- 'hello.py'
#!/usr/bin/env python
import hello
print (hello.greet())
- 'hello.cpp'
char const* greet()
{
return "hello, world";
}
#include <boost/python.hpp>
BOOST_PYTHON_MODULE(hello)
{
using namespace boost::python;
def("greet", greet);
}
基本上,我正在关注这个 repo:TNG/boost-python-examples
构建、执行:
通过bash 终端运行时,我在运行$ ./hello.so 或$ python hello.py 时遇到“分段错误(核心转储)”
abhi3700@Abhijit:/mnt/f/Coding/github_repos/cpp-playground/gitcpplibs/boost-py-eg/01-HelloWorld$ cmake .
-- Boost found.
-- Found Boost components:
python36;required
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/f/Coding/github_repos/cpp-playground/gitcpplibs/boost-py-eg/01-HelloWorld
abhi3700@Abhijit:/mnt/f/Coding/github_repos/cpp-playground/gitcpplibs/boost-py-eg/01-HelloWorld$ make
[100%] Built target hello
abhi3700@Abhijit:/mnt/f/Coding/github_repos/cpp-playground/gitcpplibs/boost-py-eg/01-HelloWorld$ ./hello.so
Segmentation fault (core dumped)
abhi3700@Abhijit:/mnt/f/Coding/github_repos/cpp-playground/gitcpplibs/boost-py-eg/01-HelloWorld$ python3 hello.py
Segmentation fault (core dumped)
abhi3700@Abhijit:/mnt/f/Coding/github_repos/cpp-playground/gitcpplibs/boost-py-eg/01-HelloWorld$
我一直在尝试解决此错误。我提到了许多解决方案,但无法解决我的一个。 有人可以帮忙吗?? 这真的很重要!!!...
谢谢!!
【问题讨论】:
-
好吧,你不能运行
.so文件。这是一个问题。 -
所以,我也尝试使用'python3 hello.py'。仍然,给出了同样的错误 - “分段错误”
-
我看到你使用了
char const*,这看起来不对...你的意思是const char*? -
实际上,根据 C++ 标准,两者都是正确的......所以,这不是原因......
-
实际上,我尝试链接该链接,但出现错误....我已经在几个小时前解决了这个问题....我会发布答案。
标签: c++ python-3.x boost cmake boost-python