[CMake] Linking boost python with mingw

Christiaan Putter ceputter at googlemail.com
Sun Dec 9 14:33:19 EST 2007


just a quick update about this in case someone else wandered about it.

I gave up trying to get boost.python to work with Python.  I'm sure it would
if I could get mingw to build Python, but the only project I could find that
was supporting this (the Python source needs to be modified apparently)
doesn't do so any more since several releases of Python because the windows
libraries supplied by python "should" be compatible. And they are, just not
with boost.python built with mingw for some reason.

So it ended up being way to much trouble to try and get boost.python to work
and I switched to Swig.

Swig works great, the cmake support could be better but there're no problems
with linking to the Python libs.

Of course some people might say that one should stick with msvc for
compiling stuff on windows because everything (is forced to) support it, and
it's free like beer.  Though when using free Qt you have to use mingw, no
way around that.  But that ain't the point, I like stuff that's free like
speech and will struggle to only use stuff that's free like speech.  Even if
it means recompiling stuff until everything else broke.


ciao

cputter



On 13/11/2007, Christiaan Putter <ceputter at googlemail.com> wrote:
>
> Thanks Pau,   I'll build Python with mingw and give it a try.
>
> I'll let you guys know how that worked out...
>
> Have a  nice evening.
>
>
> On 13/11/2007, Pau Garcia i Quiles <pgquiles at elpauer.org> wrote:
> >
> > Quoting Christiaan Putter <ceputter at googlemail.com>:
> >
> > (Returning this to the mailing list, as you mistakenly replied to me
> > in private)
> >
> > > Hi Pau,
> > >
> > > Thanks for the swift reply.
> > >
> > > From the boost website page on building boost there's a section on
> > Mingw,
> > > quoting:
> > >
> > > "If you are using a version of Python prior to 2.4.1 with a MinGW
> > prior to
> > > 3.0.0 (with binutils-2.13.90-20030111-1), you will need to create a
> > > MinGW-compatible version of the Python library; the one shipped with
> > Python
> > > will only work with a Microsoft-compatible linker..."
> > >
> > > The mingw site says something similar.
> > >
> > > I assumed this meant that using an up to date version of python (2.5)
> > and
> > > mingw meant it should work 'out of the box'.
> >
> > No, it means Python sources since 2.4 do not need to be patched to
> > build with MinGW:
> > http://www.mingw.org/MinGWiki/index.php/Python extensions
> >
> > > I forgot to mention though that I'm embedding pyhton into c++, so
> > compiling
> > > a normal c++ executable.  Also, like I said, compiling and linking
> > something
> > > using only the python25 lib works.  I'm getting errors when linking to
> > my
> > > boost.python libs.
> >
> > Most probably your problem is due to different call conventions being
> > used (__stdcall and __cdecl). Read about that here:
> > http://www.geocities.com/yongweiwu/stdcall.htm
> >
> > Either you build Python with MinGW, then try to link and make sure you
> > are providing all the libraries you need, or you try to create your
> > own import libraries for VC++-compiled Python. I'd go for the former,
> > as it will be easier.
> >
> > > In case someone else is following this thread that wants to extend
> > python:
> > >
> > > If you're compiling python code with mingw you'll have to tell it to
> > use
> > > mingw
> > > ie. something like: python setup.py build --compiler=mingw32
> > > There's a nice tutorial at
> > > http://boodebr.org/main/python/build-windows-extensions
> > >
> > > I don't know if this is applicable to embedding too.
> >
> > I have never embedded Python in an application and hardly programmed
> > anything in Python ever. I'm a Ruby guy.
> >
> > > Am I correct in assuming this Pau?
> > >
> > >
> > > On 12/11/2007, Pau Garcia i Quiles <pgquiles at elpauer.org > wrote:
> > >>
> > >> Quoting Christiaan Putter <ceputter at googlemail.com>:
> > >>
> > >> Are you using a mingw-compiled Python? In case you are using a
> > >> VC++-compiled version of Python (which is the one you download from
> > >> python.org), have you created import libraries for MinGW?
> > >>
> > >> > Hi guys and girls,
> > >> >
> > >> > I'm new to this wonderful CMake thingy and I'm having some problems
> > >> linking
> > >> > to boost.python.
> > >> >
> > >> > My setup on windows xp:
> > >> >
> > >> > mingw       5.1.3  (with gcc 3.4.5)
> > >> > boost        1.34.1
> > >> > python      2.5
> > >> >
> > >> > I compiled boost as per instructions with mingw without any
> > problems.
> > >> >
> > >> > With some simple code using boost/python I can compile without
> > errors,
> > >> but
> > >> > when ld tries linking I get "undefined reference to
> > '_imp____  ...."
> > >> errors.
> > >> >
> > >> > In my CMakeLists file I have
> > >> >
> > >> > TARGET_LINK_LIBRARIES(${EXE_NAME}
> > >> >         ${BOOST_PYTHON_LIB}
> > >> >         ${PYTHON_LIBRARIES}
> > >> >     )
> > >> >
> > >> > With the BOOST_PYTHON_LIB pointing directly to
> > >> > C:/Boost/lib/libboost_python-mgw34-1_34_1.a
> > >> >
> > >> > Removing code using boost.python stuff and just using the normal
> > python
> > >> lib
> > >> > compiles and links fine.
> > >> >
> > >> > What am I doing wrong?  I've tried every version of the
> > boost_python lib
> > >> by
> > >> > the way, -mt, -s, -d, and combinations thereof.  Which one should I
> > use,
> > >> is
> > >> > there a way to chose the correct library automatically, the
> > >> > FindBoost.cmakeinclude doesn't seem to do it.
> > >> >
> > >> > And what exactly is the -s library for? I though lib*.a files were
> > >> already
> > >> > static?
> > >> >
> > >> > If anyone out there has gotten boost.python to work with mingw
> > please
> > >> let me
> > >> > in on your secrets.  Any suggestions are welcome...
> > >> >
> > >> > Have a nice day,
> > >> > cputter
> > >> >
> > >>
> > >>
> > >>
> > >> --
> > >> Pau Garcia i Quiles
> > >> http://www.elpauer.org
> > >> (Due to my workload, I may need 10 days to answer)
> > >>
> > >> _______________________________________________
> > >> CMake mailing list
> > >> CMake at cmake.org
> > >> http://www.cmake.org/mailman/listinfo/cmake
> > >>
> > >
> >
> >
> >
> > --
> > Pau Garcia i Quiles
> > http://www.elpauer.org
> > (Due to my workload, I may need 10 days to answer)
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/cmake/attachments/20071209/8705a3df/attachment.html


More information about the CMake mailing list