boost.python compilation error (newbie)
I'm new to boost, I decided installing it by following instructions
provided at SO:
https://stackoverflow.com/a/24086375/10213771
(The only difference is that I used version 1.76)
Everything went fine, then I decided to compile this C++ file:
char const* greet(){
return "hello, world";}
#include
Hi,
On 9. Jul 2021, at 12:09, maths soso via Boost
wrote: Everything went fine, then I decided to compile this C++ file:
char const* greet(){ return "hello, world";} #include
BOOST_PYTHON_MODULE(hello_ext){ using namespace boost::python; def("greet", greet);}
there is a separate user-list for questions like this, see https://www.boost.org/community/groups.html This list is for Boost developers as explained on that page. The cpplang slack cpplang.slack.com is also a good source for help, look for the boost-user channel. Best regards, Hans
On 7/9/21 1:09 PM, maths soso via Boost wrote:
I'm new to boost, I decided installing it by following instructions provided at SO: https://stackoverflow.com/a/24086375/10213771 (The only difference is that I used version 1.76) Everything went fine, then I decided to compile this C++ file:
char const* greet(){ return "hello, world";} #include
BOOST_PYTHON_MODULE(hello_ext){ using namespace boost::python; def("greet", greet);}
Since boost.python is not header only library, I needed to link to it on compilation, I used the following compile command: g++ -I ~/Desktop/boost_1_76_0/ -I /usr/include/python2.7/ main.cpp -o prog ~/Desktop/boost_1_76_0/stage/lib/libboost_python27.a
but I get the following errors: /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x24): undefined reference to `main' /usr/bin/ld: /home/sofiane/Desktop/boost_1_76_0/stage/lib/libboost_python27.a(registry.o): in function `boost::python::converter::registration::get_class_object() const': ... /usr/bin/ld: function_doc_signature.cpp:(.text+0x1de): undefined reference to `PyObject_IsTrue' /usr/bin/ld: function_doc_signature.cpp:(.text+0x23e): undefined reference to `PyInt_FromLong' /usr/bin/ld: function_doc_signature.cpp:(.text+0x28b): undefined reference to `PyInt_FromLong'
I'm not a Python expert, but it looks like: 1. You are not linking to the python library that implements the missing symbols. 2. You are missing `main` function or the -c compiler option to indicate that you want to only compile the file, not link it.
participants (3)
-
Andrey Semashev
-
Hans Dembinski
-
maths soso