Make fail: recompile with -fpic

Hi, I am having difficulties installing channelflow. I’ve used the cmake command to build the makefile and instalation files, however when i run make -j it returns an error related to linking static and dynamic libraries:

/usr/bin/ld: /usr/local/lib/libfftw3_mpi.a(api.o): relocation R_X86_64_32S against `ompi_mpi_comm_null’ can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libfftw3_mpi.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
channelflow/CMakeFiles/chflow.dir/build.make:653: recipe for target ‘channelflow/libchflow.so’ failed
make[2]: *** [channelflow/libchflow.so] Error 1
CMakeFiles/Makefile2:384: recipe for target ‘channelflow/CMakeFiles/chflow.dir/all’ failed
make[1]: *** [channelflow/CMakeFiles/chflow.dir/all] Error 2
Makefile:138: recipe for target ‘all’ failed
make: *** [all] Error 2

The compiler reccomends i include the -fPIC command, however I can’t find a way to modify either the makefile, or the cmake commands to do this.

I’ve also tried using -DWITH_STATIC=ON and -DWITH_SHARED=OFF to only create static libraries, but that didn’t seem to work. Heres the output of that command:

sjter1@MU00140044L:~/Cbuild$ cmake …/channelflow -DCMAKE_BUILD_TYPE=release -DUSE_MPI=ON -DWITH_STATIC=ON -DWITH_SHARED=OFF -DWITH_HDF5CXX=ON

– configuring channelflow version 2.0.2
– Using GNU compiler options

– Starting system introspection
– Found FFTW
– FFTW_LIBRARY=/usr/local/lib/libfftw3.a
– FFTW_OMP_LIBRARY=/usr/lib/x86_64-linux-gnu/libfftw3_omp.a
– FFTW_MPI_LIBRARY=/usr/local/lib/libfftw3_mpi.a
– MPI libs: /usr/lib/openmpi/lib/libmpi_cxx.so;/usr/lib/openmpi/lib/libmpi.so
– FFTW_MPI library: /usr/local/lib/libfftw3_mpi.a
– NetCDF include dir: /usr/include
– Checking if hdf5 library functions in are working correctly.

– Include directories:
– Git revision 9f099a4079b8ffe8b22128afc4f6b02bae9a0b7f
– Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)

###############################################
########### Configuration summary ###########
###############################################
Compiler: GNU 5.4.0
Build type: release
Install prefix: /usr/local
Building shared library: yes
Linking programs to: shared library

Libraries
MPI: enabled
netcdf (default file format): enabled
Parallel netcdf: disabled
HDF5 C++ (legacy file format): enabled

Channelflow components
nsolver: enabled
Python wrapper: disabled
GTest unit testing: enabled

– Configuring done
– Generating done
– Build files have been written to: /home/sjter1/Cbuild

Any idea what I can do to fix this?

Hi,

To give flags to the compiler you can add something like

-DCMAKE_BUILD_TYPE=release -DCMAKE_CXX_FLAGS_RELEASE:STRING="-fPIC"

to your cmake call. I don’t know if that will fix it though necessarily. I usually find that these sorts of linker problems can be fixed trying different versions of libfftw3 and mpi (and sometimes gcc). If you’re on HPC see if you can swap out some different modules. Not a very intelligent solution but it can work!

Maybe someone else can add some more insight. You might also check to see if it compiles and links successfully in serial mode too.

I this is an old post but I still wish to bump it up as I had the same issues which i fixed. I reinstalled my all my fftw libraries from statically compiled (.a files) to dynamically compiled (.so files) and manage to get pass this error

To be more specific, configure fftw with --enable-shared