Nahuel Defossé | 13 Dec 15:03 2010
Picon

Linking against static library in specific path

I'm trying to wrap some existing C++ code which is compiled and bundled in static .a libraries.

I've followed the guide exposed at http://wiki.cython.org/WrappingCPlusPlus and I wrote down this
setup.py file:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
  name = 'ipcbus',
  ext_modules=[
    Extension("ipcbus",
              sources=["ipcbus.pyx", "../lib/ipcbus/ipcbus_message.cpp"], # Note, you can link against a c++ library instead of including the source
              include_dirs=["../lib/ipcbus"],
              libraries = ["../lib/ipcbus.a",],
              #extra_link_args = ["../lib/libipcbus.a",],
              language="c++"),
    ],
  cmdclass = {'build_ext': build_ext},

)

Am I getting something wrong? libipcbus.a is a static lib, and though it compiles fine, I get some undefined symbols errors.

The library, as the above text shows is located in ../lib/.

Thanks
Nahuel Defossé | 13 Dec 15:29 2010
Picon

Re: Linking against static library in specific path

I found the answer, I had to add extra_objects to the Extension call, like this:


setup(
  name = 'ipcbus',
  ext_modules=[
    Extension("ipcbus",
              sources=["ipcbus.pyx", "../lib/ipcbus/ipcbus_message.cpp"], # Note, you can link against a c++ library instead of including the source
              include_dirs=["../lib/ipcbus"],
              libraries = ["../lib/ipcbus.a",],
              language="c++",
              extra_objects=["../lib/libipcbus.a"],),
    ],
  cmdclass = {'build_ext': build_ext},

)


Sorry for bothering you


2010/12/13 Nahuel Defossé <nahuel.defosse <at> gmail.com>
I'm trying to wrap some existing C++ code which is compiled and bundled in static .a libraries.
I've followed the guide exposed at http://wiki.cython.org/WrappingCPlusPlus and I wrote down this
setup.py file:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
  name = 'ipcbus',
  ext_modules=[
    Extension("ipcbus",
              sources=["ipcbus.pyx", "../lib/ipcbus/ipcbus_message.cpp"], # Note, you can link against a c++ library instead of including the source
              include_dirs=["../lib/ipcbus"],
              libraries = ["../lib/ipcbus.a",],
              #extra_link_args = ["../lib/libipcbus.a",],
              language="c++"),
    ],
  cmdclass = {'build_ext': build_ext},

)

Am I getting something wrong? libipcbus.a is a static lib, and though it compiles fine, I get some undefined symbols errors.

The library, as the above text shows is located in ../lib/.

Thanks

Lisandro Dalcin | 13 Dec 22:53 2010
Picon

Re: Re: Linking against static library in specific path

2010/12/13 Nahuel Defossé <nahuel.defosse <at> gmail.com>:
> I found the answer, I had to add extra_objects to the Extension call, like
> this:
> setup(
>   name = 'ipcbus',
>   ext_modules=[
>     Extension("ipcbus",
>               sources=["ipcbus.pyx", "../lib/ipcbus/ipcbus_message.cpp"], #
> Note, you can link against a c++ library instead of including the source
>               include_dirs=["../lib/ipcbus"],
>               libraries = ["../lib/ipcbus.a",],
>               language="c++",
>               extra_objects=["../lib/libipcbus.a"],),
>     ],
>   cmdclass = {'build_ext': build_ext},
> )
> I found the answer in
> Stackoverflow: http://stackoverflow.com/questions/2105508/wrap-c-lib-with-cython
> Sorry for bothering you
>

Are you sure you need  "libraries = ["../lib/ipcbus.a",]" ??

> 2010/12/13 Nahuel Defossé <nahuel.defosse <at> gmail.com>
>>
>> I'm trying to wrap some existing C++ code which is compiled and bundled in
>> static .a libraries.
>> I've followed the guide exposed
>> at http://wiki.cython.org/WrappingCPlusPlus and I wrote down this
>> setup.py file:
>> from distutils.core import setup
>> from distutils.extension import Extension
>> from Cython.Distutils import build_ext
>> setup(
>>   name = 'ipcbus',
>>   ext_modules=[
>>     Extension("ipcbus",
>>               sources=["ipcbus.pyx", "../lib/ipcbus/ipcbus_message.cpp"],
>> # Note, you can link against a c++ library instead of including the source
>>               include_dirs=["../lib/ipcbus"],
>>               libraries = ["../lib/ipcbus.a",],
>>               #extra_link_args = ["../lib/libipcbus.a",],
>>               language="c++"),
>>     ],
>>   cmdclass = {'build_ext': build_ext},
>> )
>> Am I getting something wrong? libipcbus.a is a static lib, and though it
>> compiles fine, I get some undefined symbols errors.
>> The library, as the above text shows is located in ../lib/.
>> Thanks
>

--

-- 
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169

Saúl Ibarra Corretgé | 13 Dec 23:50 2010
Picon

" __builtin__.str has the wrong size, try recompiling" with Python 2.7

Hi,

I'm trying to run some code I have currently built with Cython 0.12.1
and Python 2.6 on Python 2.7. Compilation works just fine, but on
runtime I'm getting the following error:

File "_core.pxd", line 31, in init sipsimple.core._core
(sipsimple/core/_core.c:154990)
ValueError: __builtin__.str has the wrong size, try recompiling

On the pxd file this is what I have on line 31:

cdef extern from "stringobject.h":
    ctypedef class __builtin__.str [object PyStringObject]:
        pass

This has worked for a long time so far. Is this a bug on Cython
0.12.1? If so, has it been fixed in further releases?

Thanks a lot for any clarification,

--

-- 
/Saúl
http://saghul.net | http://sipdoc.net


Gmane