alfa_80
alfa_80

Reputation: 427

Command to compile using libboost_python on ubuntu

I am trying to compile my code using libboost library, by putting #include <boost/python.hpp> in my C++ code. Could somebody please help me the right command to run this, especially to include and link the library. I'm pretty basic in this.

The command used(but not working):

g++ try.cpp -L /usr/lib/libboost_python.so -o try

EDIT:

The tested code:

#include <boost/python.hpp>
#include <iostream>

int main() 
{

    std::cout << "Yes, it works :-)" << std::endl;

    return 0;
}

Error messages:

from try.cpp:1:
/usr/include/boost/python/enum.hpp:31: error: expected ‘;’ before ‘*’ token
/usr/include/boost/python/enum.hpp:32: error: expected ‘;’ before ‘(’ token
/usr/include/boost/python/enum.hpp:33: error: ‘PyObject’ has not been declared
/usr/include/boost/python/enum.hpp:52: error: expected constructor, destructor, or     type conversion before ‘*’ token
/usr/include/boost/python/enum.hpp:67: error: ‘void*       boost::python::enum_<T>::convertible_from_python’ is not a static member of ‘struct     boost::python::enum_<T>’
/usr/include/boost/python/enum.hpp:67: error: template definition of non-template ‘    void* boost::python::enum_<T>::convertible_from_python’
/usr/include/boost/python/enum.hpp:67: error: ‘PyObject’ was not declared in this     scope
/usr/include/boost/python/enum.hpp:67: error: ‘obj’ was not declared in this scope
    /usr/include/boost/python/enum.hpp:80: error: variable or field ‘construct’     declared void 
/usr/include/boost/python/enum.hpp:80: error: ‘PyObject’ was not declared in this     scope
/usr/include/boost/python/enum.hpp:80: error: ‘obj’ was not declared in this scope
/usr/include/boost/python/enum.hpp:80: error: expected primary-expression before ‘*’ token
/usr/include/boost/python/enum.hpp:80: error: ‘data’ was not declared in this scope

Another thing is that when I compile g++ -Wall thread_one.cpp -o thread_one -lboost_thread, that works in order to use boost_thread library.

Upvotes: 1

Views: 882

Answers (2)

alfa_80
alfa_80

Reputation: 427

Finally, it is working. The command used is as below:

g++ -I/usr/include/python2.6 try.cpp -o try -lboost_python -lpython2.6

Upvotes: 1

Kerrek SB
Kerrek SB

Reputation: 477040

Try this:

g++ try.cpp -o try -lboost_python

It'd be good style to also add -W -Wall -Wextra -pedantic to your compiler invocation (so that your next SO question can be more specific :-)). Also, -O2 or -O3 for optimization is probably a very good idea, especially with Boost. Finally, splitting the building up into separate stages makes recompiling faster when you have multiple files:

g++ -c -o try.o try.cpp -W -Wall -Wextra -pedantic -O2
g++ -o try try.o -s -lboost_python

Upvotes: 1

Related Questions