linker problems with c++ wrapper

157 views
Skip to first unread message

ptone

unread,
Oct 23, 2010, 12:28:48 AM10/23/10
to cython-users
I've been able to build other people's extensions based on cython, so
I know the fundamentals of my setup are OK. I was taking a stab at
wrapping a c++ wrapper today and ran into problems with the linker not
finding a library.

Now I'm sure my pyx file is not perfect, but cython does output a .cpp
file, and gcc compiles this into a .o file. But when g++ gets
involved and goes to do the linking, I get an error that the library
can't be found (once per arch).

I've played with the g++ call and added various versions of -L and
have triple checked that the library is there an intact. The command
line tools that use this library are working fine - so I believe the
lib is there and functioning just fine.

This is on OS X with latest updates and dev tools

Here is the output from running setup.py build_ext:

running build_ext
cythoning cola.pyx to cola.cpp
building 'cola' extension
creating build
creating build/temp.macosx-10.6-universal-2.6
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -
Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch ppc -
arch x86_64 -pipe -I/System/Library/Frameworks/Python.framework/
Versions/2.6/include/python2.6 -c cola.cpp -o build/temp.macosx-10.6-
universal-2.6/cola.o
cc1plus: warning: command line option "-Wstrict-prototypes" is valid
for C/ObjC but not for C++
cc1plus: warning: command line option "-Wstrict-prototypes" is valid
for C/ObjC but not for C++
cc1plus: warning: command line option "-Wstrict-prototypes" is valid
for C/ObjC but not for C++
g++-4.2 -Wl,-F. -bundle -undefined dynamic_lookup -arch i386 -arch ppc
-arch x86_64 build/temp.macosx-10.6-universal-2.6/cola.o -llibola -o
cola.so
ld: library not found for -llibola
collect2: ld returned 1 exit status
ld: library not found for -llibola
collect2: ld returned 1 exit status
ld: library not found for -llibola
collect2: ld returned 1 exit status
lipo: can't open input file: /var/folders/KP/KPrqza+tEJG955pHKlCFwE++
+TI/-Tmp-//cc1NVxQ4.out (No such file or directory)
error: command 'g++-4.2' failed with exit status 1

for background I'm trying to get a basic wrapper around the open
lighting architecture library's (opendmx.net) streaming client.

-Preston

Robert Bradshaw

unread,
Oct 23, 2010, 4:13:45 AM10/23/10
to cython...@googlegroups.com
On Fri, Oct 22, 2010 at 9:28 PM, ptone <pre...@ptone.com> wrote:
> I've been able to build other people's extensions based on cython, so
> I know the fundamentals of my setup are OK.  I was taking a stab at
> wrapping a c++ wrapper today and ran into problems with the linker not
> finding a library.
>
> Now I'm sure my pyx file is not perfect, but cython does output a .cpp
> file, and gcc compiles this into a .o file.  But when g++ gets
> involved and goes to do the linking, I get an error that the library
> can't be found (once per arch).
>
> I've played with the g++ call and added various versions of -L and
> have triple checked that the library is there an intact.  The command
> line tools that use this library are working fine - so I believe the
> lib is there and functioning just fine.

If you need -L... from the command line, you probably need
library_dirs=[...] in your setup.py.

ptone

unread,
Oct 23, 2010, 12:44:04 PM10/23/10
to cython-users


On Oct 23, 1:13 am, Robert Bradshaw <rober...@math.washington.edu>
wrote:
> On Fri, Oct 22, 2010 at 9:28 PM, ptone <pres...@ptone.com> wrote:
> > I've been able to build other people's extensions based on cython, so
> > I know the fundamentals of my setup are OK.  I was taking a stab at
> > wrapping a c++ wrapper today and ran into problems with the linker not
> > finding a library.
>
> > Now I'm sure my pyx file is not perfect, but cython does output a .cpp
> > file, and gcc compiles this into a .o file.  But when g++ gets
> > involved and goes to do the linking, I get an error that the library
> > can't be found (once per arch).
>
> > I've played with the g++ call and added various versions of -L and
> > have triple checked that the library is there an intact.  The command
> > line tools that use this library are working fine - so I believe the
> > lib is there and functioning just fine.
>
> If you need -L... from the command line, you probably need
> library_dirs=[...] in your setup.py.

Yup - tried various combinations of library_dirs in setup.py and -L
flag directly in a g++ command. The library in question is there in /
usr/local/lib. So I'll admit this probably isn't an issue with cython
per se, except other than basic configure/make of distributions, I
don't interact much with gcc - and it seems like there is a chance
that this is something to do with how cython is calling gcc then g++??

I can post a complete file set somewhere if someone who has OS X is
willing to try and replicate. The library I'm building against (OLA)
can also be built for linux, but there is a binary installer for os x
(that does install the include files as well).

-Preston

Robert Bradshaw

unread,
Oct 23, 2010, 1:24:19 PM10/23/10
to cython...@googlegroups.com
On Sat, Oct 23, 2010 at 9:44 AM, ptone <pre...@ptone.com> wrote:
>
>
> On Oct 23, 1:13 am, Robert Bradshaw <rober...@math.washington.edu>
> wrote:
>> On Fri, Oct 22, 2010 at 9:28 PM, ptone <pres...@ptone.com> wrote:
>> > I've been able to build other people's extensions based on cython, so
>> > I know the fundamentals of my setup are OK.  I was taking a stab at
>> > wrapping a c++ wrapper today and ran into problems with the linker not
>> > finding a library.
>>
>> > Now I'm sure my pyx file is not perfect, but cython does output a .cpp
>> > file, and gcc compiles this into a .o file.  But when g++ gets
>> > involved and goes to do the linking, I get an error that the library
>> > can't be found (once per arch).
>>
>> > I've played with the g++ call and added various versions of -L and
>> > have triple checked that the library is there an intact.  The command
>> > line tools that use this library are working fine - so I believe the
>> > lib is there and functioning just fine.
>>
>> If you need -L... from the command line, you probably need
>> library_dirs=[...] in your setup.py.
>
> Yup - tried various combinations of library_dirs in setup.py and -L
> flag directly in a g++ command.  The library in question is there in /
> usr/local/lib.

To clarify, were you or were you not able to get it to compile
directly be adding the -L option and invoking g++ directly? If not,
there's nothing much from Cython you can do. Perhaps try to make a
hello world and see if you can get that to link against libola as
another simplifying step.

> So I'll admit this probably isn't an issue with cython
> per se, except other than basic configure/make of distributions, I
> don't interact much with gcc - and it seems like there is a chance
> that this is something to do with how cython is calling gcc then g++??

Cython doesn't actually call g++, it just creates the .cpp file and
then its job is over. (Distutils calls g++.)

> I can post a complete file set somewhere if someone who has OS X is
> willing to try and replicate.  The library I'm building against (OLA)
> can also be built for linux, but there is a binary installer for os x
> (that does install the include files as well).

Were you able to get your Cython file to compile under linux (as
another data point)?

- Robert

Reply all
Reply to author
Forward
0 new messages