Error while linking `_XdmfCore.so` without selecting to build shared library...
If BUILD_SHARED_LIBS
is not set while configuring a build then linking _XdmfCore.so
fails with the following error message:
[ 98%] Linking CXX shared module ../_XdmfCore.so
/bin/ld: libXdmfCore.a(XdmfArray.cpp.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
libXdmfCore.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
core/CMakeFiles/_XdmfCorePython.dir/build.make:106: recipe for target '_XdmfCore.so' failed
make[2]: *** [_XdmfCore.so] Error 1
CMakeFiles/Makefile2:199: recipe for target 'core/CMakeFiles/_XdmfCorePython.dir/all' failed
make[1]: *** [core/CMakeFiles/_XdmfCorePython.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[100%] Linking CXX shared module _Xdmf.so
/bin/ld: libXdmf.a(XdmfAttribute.cpp.o): relocation R_X86_64_32 against `_ZTV13XdmfAttribute' can not be used when making a shared object; recompile with -fPIC
libXdmf.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
CMakeFiles/_XdmfPython.dir/build.make:107: recipe for target '_Xdmf.so' failed
make[2]: *** [_Xdmf.so] Error 1
CMakeFiles/Makefile2:105: recipe for target 'CMakeFiles/_XdmfPython.dir/all' failed
make[1]: *** [CMakeFiles/_XdmfPython.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
For example, the above error can be reproduced by using the following commands to configure and build XDMF:
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=${XDMF_INSTALL_DIR} \
-DBUILD_SHARED_LIBS=0 -DXDMF_WRAP_PYTHON=1 -Wno-dev
make
As seen from the error message, the build tries to link a shared object file using libXdmfCore.a
which results in an error. This error goes away if BUILD_SHARED_LIBS
is set. The build scripts should either automatically build the shared library if it is essential or display a clearer error message to the user asking them to enable building the shared library.