This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Howto build static libraries? - linking swig modules fails

0 votes

Hi,

i'm trying to build a static version of dolfin. I set BUILD_SHARED_LIBS to off, but compilation fails with

Building CXX object dolfin/swig/modules/la/CMakeFiles/_la.dir/modulePYTHON_wrap.cxx.o
Linking CXX shared module _la.so
/usr/bin/ld: /lrz/sys/tools/python/2.7.4/lib/libpython2.7.a(abstract.o): relocation R_X86_64_32S against `_Py_NotImplementedStruct' can not be used when making a shared object; recompile with -fPIC
/lrz/sys/tools/python/2.7.4/lib/libpython2.7.a: could not read symbols: Bad value

so, while creating the libdolfin.a works, an option like --shared-libgcc is still passed to the compiler when building the swig modules. Now, is this a bug, do i have to set another option to off, or does exist a workaround?

I greped for shared-libgcc to find where this option is set, but it only returns entries from the CMakeOutput.log. I searched the dolfin/swig/modules/*/CMakeLists.txt for a possibility to change this, but still no luck.

I actually could recompile the needed libraries with -fpic as the message suggests, and this worked already for similar errors, but: First, recompiling every library is timeconsuming, as i only can login to the cluster with ssh, and no library is placed i s placed in an usual location, als "/lrz/sys/tools/python/2.7.4/lib/libpython2.7.a" already suggests. Second, there are libraries i can't recompile (like python) due to me not having root access, third, this would still build shared libs from the swig modules, and final reason is -fpic can make applications significantly slower.

asked Dec 10, 2013 by Xelf FEniCS Novice (150 points)

1 Answer

+2 votes
 
Best answer

There is no point compiling the python wrappers as static libraries as they have to be shared to work as Python extension modules. So either go full shared or turn off Python wrappers.

answered Dec 10, 2013 by johanhake FEniCS Expert (22,480 points)
selected Dec 12, 2013 by Xelf
...