Note that there are some explanatory texts on larger screens.

plurals
  1. POundefined reference in basic boost:pyton program
    primarykey
    data
    text
    <p>I wanted to start using boost:python to embed python in my C++ program, but I am already having problems with this simple code:</p> <pre><code>#include &lt;boost/python.hpp&gt; //boost libraries #include &lt;Python.h&gt; //python libraries using namespace boost::python; int main() { Py_Initialize(); object main_module = import("__main__"); object main_namespace = main_module.attr("__dict__"); return 0; } </code></pre> <p>I'm just starting the interpreter and importing the main module but the compiler already have problems with that:</p> <pre><code>/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&amp;, char const*)' </code></pre> <p>I don't have a clue why I am getting those errors. I am pretty sure boost:python is built correctly.</p> <p>Anyone able to enlight me?</p> <p>I am using QT creator to build and compile. If I compile using G++ with <code>-I/usr/include -I/usr/include/python2.6 main.cpp</code> I get:</p> <pre><code>/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&amp;, char const*)': main.cpp:(.text._ZN5boost6python3api24const_attribute_policies3getERKNS1_6objectEPKc[boost::python::api::const_attribute_policies::get(boost::python::api::object const&amp;, char const*)]+0x26): undefined reference to `boost::python::api::getattr(boost::python::api::object const&amp;, 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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload