[C++-sig] CMake and getting starting with boost.python

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[C++-sig] CMake and getting starting with boost.python

braddock
Yesterday I became a boost.python user, after years of heavy SWIG usage.
I would have started using boost.python years ago except for the bjam
learning curve.  I spent hours TRYING on multiple occasions, but got lost
every time trying to get the page one example to build with bjam.

Here is how to build the "greet" example with a four line CMake file:

cat >>CMakeLists.txt <<EOF
LINK_LIBRARIES(boost_python)
INCLUDE_DIRECTORIES("/usr/include/python2.5")
LINK_DIRECTORIES("/usr/lib/python2.5") # Not needed?
ADD_LIBRARY(hello SHARED hello.cpp)
EOF

You WILL have to `mv libhello.so hello.so` after building.

Works for me under Ubuntu Linux 6.10 after
apt-get install cmake python2.5-dev boost-python-dev
cmake
make
mv libhello.so hello.so

ipython
In [1]: import hello
In [2]: hello.greet()
Out[2]: 'hello, world'

Boost.Python has been a joy to learn and use since I got past bjam.
I had a moderately large API wrapped in just my first couple hours of
learning (less time than I spent messing with bjam).

Any additional advice for using CMake to build boost.python?

Braddock Gaskill


_______________________________________________
C++-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/c++-sig
Reply | Threaded
Open this post in threaded view
|

Re: [C++-sig] CMake and getting starting with boost.python

braddock
For those who prefer Makefiles, I found the following Makefile also worked
to build the greet example.  It is based on some Makefiles posted to this
list.  I don't know how robust it is.  Worked under Linux Ubuntu 6.10.


CC = g++

CFLAGS = -Wall -W -fPIC -I/usr/include/boost \
        -I/usr/include/python2.5 -DBOOST_PYTHON_DYNAMIC_LIB \
        -O2

LDFLAGS = -L/usr/local/lib -lboost_python -L/usr/lib/python2.5 \
        -Wl,-rpath-link,.  -fPIC

CXXFLAGS = $(CFLAGS)

SLIB = hello.so

all: $(SLIB)

%.so : %.o
        /usr/bin/objcopy --set-section-flags .debug_str=contents,debug $^
        $(CC) $(LDFLAGS) $^ -shared -o $@

clean :
        rm -f $(WORLD) $(OBJS)




_______________________________________________
C++-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/c++-sig
Reply | Threaded
Open this post in threaded view
|

Re: [C++-sig] CMake and getting starting with boost.python

francesco biscani-2
In reply to this post by braddock
On Friday 29 June 2007, Braddock Gaskill wrote:
> LINK_LIBRARIES(boost_python)
> INCLUDE_DIRECTORIES("/usr/include/python2.5")
> LINK_DIRECTORIES("/usr/lib/python2.5") # Not needed?
> ADD_LIBRARY(hello SHARED hello.cpp)
> EOF
>
> You WILL have to `mv libhello.so hello.so` after building.
>

You can avoid renaming the shared object like this:

SET_TARGET_PROPERTIES(hello PROPERTIES PREFIX "")

This way the shared library won't have the "lib" prefix.

BTW, I'm using CMake + Boost.Python and I'm happy about it, the only issue I
have is that I can't compile it under Windows (MinGW) because of some
dllimport errors. Have you had any experience about it?

Regards,

  Francesco.
_______________________________________________
C++-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/c++-sig
Reply | Threaded
Open this post in threaded view
|

Re: [C++-sig] CMake and getting starting with boost.python

fjanoos
In reply to this post by braddock
Dear Braddock,

I'm trying to build Python wrappers with Boost for a fairly large C++ project - and most of its configuration is in CMake. Do you have any more information on using Boost Python through cmake.

Specifically - i'm interested in configuring cmake to auto-detect (or atleast require) the boost installation and necessary libraries.

thanks,
-fj
Reply | Threaded
Open this post in threaded view
|

Re: CMake and getting starting with boost.python

Tyler Weston
Try this. I believe the required FindBoost.cmake is standard in the cmake/shared/cmake-x.y/modules. Not all of these options may apply to your build.

#
# BOOST
#
set(Boost_USE_STATIC_LIBS        OFF)
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME     OFF)
set(BOOST_ROOT "path/to/boost")
# uncomment to debug find_package(Boost): 
# set(Boost_DEBUG TRUE)
find_package(Boost 1.46.1 COMPONENTS system filesystem regex date_time thread serialization python )



On Fri, Aug 5, 2011 at 2:53 PM, fjanoos <[hidden email]> wrote:
Dear Braddock,

I'm trying to build Python wrappers with Boost for a fairly large C++
project - and most of its configuration is in CMake. Do you have any more
information on using Boost Python through cmake.

Specifically - i'm interested in configuring cmake to auto-detect (or
atleast require) the boost installation and necessary libraries.

thanks,
-fj

--
View this message in context: http://boost.2283326.n4.nabble.com/C-sig-CMake-and-getting-starting-with-boost-python-tp2700144p3722133.html
Sent from the Python - c++-sig mailing list archive at Nabble.com.
_______________________________________________
Cplusplus-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/cplusplus-sig


_______________________________________________
Cplusplus-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/cplusplus-sig