I wanted to start using boost:python to embed python in my C++ program, but I am already having problems with this simple code:
#include <boost/python.hpp> //boost libraries
#include <Python.h> //python libraries
using namespace boost::python;
int main()
{
Py_Initialize();
object main_module = import("__main__");
object main_namespace = main_module.attr("__dict__");
return 0;
}
I’m just starting the interpreter and importing the main module but the compiler already have problems with that:
/home/i7941878/Code/pythonTest/main.cpp:-1: error: undefined reference to `boost::python::detail::str_base::str_base(char const*)'
/home/i7941878/Code/pythonTest/main.cpp:-1: error: undefined reference to `boost::python::import(boost::python::str)'
/home/i7941878/Code/pythonTest/main.cpp:-1: error: undefined reference to `boost::python::api::getattr(boost::python::api::object const&, char const*)'
I don’t have a clue why I am getting those errors. I am pretty sure boost:python is built correctly.
Anyone able to enlight me?
I am using QT creator to build and compile.
If I compile using G++ with -I/usr/include -I/usr/include/python2.6 main.cpp I get:
/tmp/ccI8x97b.o: In function `main':
main.cpp:(.text+0xc): undefined reference to `Py_Initialize'
main.cpp:(.text+0x30): undefined reference to `boost::python::import(boost::python::str)'
/tmp/ccI8x97b.o: In function `boost::python::api::object::object()':
main.cpp:(.text._ZN5boost6python3api6objectC2Ev[_ZN5boost6python3api6objectC5Ev]+0xd): undefined reference to `_Py_NoneStruct'
/tmp/ccI8x97b.o: In function `boost::python::api::const_attribute_policies::get(boost::python::api::object const&, char const*)':
main.cpp:(.text._ZN5boost6python3api24const_attribute_policies3getERKNS1_6objectEPKc[boost::python::api::const_attribute_policies::get(boost::python::api::object const&, char const*)]+0x26): undefined reference to `boost::python::api::getattr(boost::python::api::object const&, char const*)'
/tmp/ccI8x97b.o: In function `boost::python::str::str(char const*)':
main.cpp:(.text._ZN5boost6python3strC2EPKc[_ZN5boost6python3strC5EPKc]+0x1f): undefined reference to `boost::python::detail::str_base::str_base(char const*)'
collect2: ld returned 1 exit status
I think we really need the way in which you are compiling the code. Have you specified the boost includes?