Minimal Boost Python example not working
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 32/100
Research direction
Run the shown C++20 Boost.Python module with Python 3.10 and the my_module.printStr call, then inspect the boundary around def("printStr", printStr) and the std::string conversion. Capture the build and runtime configuration needed to reproduce the fault, and confirm completion when the call prints BEFORE, the message, and AFTER without a segmentation fault.
Written by the indexing model from the issue text.
Description
I'm having trouble getting boost python to work with this minimal example. I've emailed the mailing list but have had no response.
I'm using C++20
#include <boost/python.hpp>
#include <iostream>
#include <string>
void printStr(const std::string &testStr) {
std::cout << "BEFORE" <<std::endl;
std::cout << testStr <<std::endl;
std::cout << "AFTER" <<std::endl;
}
BOOST_PYTHON_MODULE(my_module) {
using namespace boost::python;
def("printStr", printStr);
}
This compiles fine, but I get a segmentation fault when I attempt to call the function from python (using 3.10):
import my_module
message = "This is a test"
my_module.printStr(message)
The output I get:
BEFORE
Segmentation fault
Can you tell me what I'm doing wrong? Thanks in advance
- Dominant language
- C++
- Stars
- 537
- Forks
- 223
- Avg merge
- 11h 22m
- Merged PRs (30d)
- 2
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/python
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
-
BoostDetectToolset-1.90.0.cmake file not found in an include() call in boost_python-config.cmake Open
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
objectionary/eo-graphs#74 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
enhancement
Difficulty 1/5 Under an hour Newbie friendliness 88/100
QuantStack/git2cpp#187 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100