Creating Cython results in undefined character

I have a C ++ program that I am trying to wrap / convert in Cython. It uses a specific library, which for some reason will not lead to the creation of a working module for import. By the way, there is a working program in C ++. Here is setup.py:

ext_modules = [ Extension( name="libnmfpy", sources=["interface/nmf_lib.pyx"], include_dirs = ["../src/", numpy.get_include()], libraries=["nmf","mpi_cxx","mpi","m"], library_dirs=["../build/Linux/bin.release","/usr/local/lib/","/usr/lib"], language="c++",) ] setup( name = 'libnmfpy', cmdclass = {'build_ext': build_ext}, ext_modules = ext_modules, ) 

I should mention that it is libnmf, which seems to be causing problems. The first build of libnmf will cause this script to generate this error:

 /usr/bin/ld: ../build/Linux/bin.release/libnmf.a(nmf.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC ../build/Linux/bin.release/libnmf.a: could not read symbols: Bad value collect2: error: ld returned 1 exit status 

When I rebuild libnmf with -fPIC, setup generates libnmfpy.so, but when I import it into another script, I would get the above undefined character:

 Traceback (most recent call last): File "test.py", line 1, in <module> import libnmfpy ImportError: $path/cython/libnmfpy.so: undefined symbol: _ZN4elem6lapack3SVDEiiPdiS1_ 

If that helped, here is what my search suggested:

 nm libnmfpy.so | grep _ZN4elem6lapack3SVDEiiPdiS1_ U _ZN4elem6lapack3SVDEiiPdiS1_ nm ../build/Linux/bin.release/libnmf.a | grep _ZN4elem6lapack3SVDEiiPdiS1_ U _ZN4elem6lapack3SVDEiiPdiS1_ 

Here is what I think about the cause of the error. I look at what I think is the offensive library libnmf is built on:

 nm $another_path/lib/libelemental.a | grep _ZN4elem6lapack3SVDEiiPdiS1_ 0000000000005290 T _ZN4elem6lapack3SVDEiiPdiS1_ 

I am still not very familiar with libraries and linkers, so any help would be appreciated. Thanks

edit: a little digging made me understand something. Is there a difference between Mac OS X and Linux that I have to keep track of? The people I'm working on wrote this, initially reported build errors like this

+6
source share
2 answers

You must use nm -C to untie the characters. It also looks like you're mixing static and shared libraries, which is usually not a good idea. In addition, the gcc linker is a one-pass linker, which means the order of the library flags. You want to list the libraries in reverse order. In other words, if a depends on b, then b should appear before a in the linker flags.

+3
source

Well, I can’t try to recreate your setup and then work out and test the solution on my installation, since I don’t have your source, but it seems to me that when you recompiled libnmf using fpic, it was recompiled using dynamic linking, then as before he was statically connected.

If my assumption is correct, you can try:

  • compile libnmf again with -fPIC , AND -static .
  • by changing your setup.py - add "elemental" to the libraries list - this will make the linker also extract this lib.

It should be noted that approach No. 1 is usually considered less desirable, but, as I said, it may be that it was originally compiled in this way. # 2, however, may take more work, because if there are other libraries that are needed, you will also have to find and add them.

+1
source

All Articles