Failed linking attempt with FORTRAN and C++ (using MPI)

395 views
Skip to first unread message

Carlos Felipe Forigua Rodriguez

unread,
Oct 2, 2016, 11:12:49 AM10/2/16
to Cantera Users' Group
Dear Users and Developers, 

With your help I've managed to use Cantera in C++ with FORTRAN in order to solve many reactors generated by the CFD software KIVA-4. I'm not trying to solve large mechanisms but many  reactors  with small mechanisms.

My setup is Lubuntu linux 16.04 + Cantera 2.2.2b1 + Intel compilers 2016 + sundials 2.6 + python 3.5.2 + boost 1.61 + OpenMPI 2.0.1. It works like a charm and even I can use OpenMP.

I have tested MPI linking C++ to FORTRAN with this code. It worked with these compiling instructions:

#Compile
mpicc -c quad_sub.c
mpif90 quad_sub.o quad_main.f90 -o programa
#run
mpirun -np 8 ./programa

I tried is to compile everything with OpenMPI. So I just made a code that calls some MPI functions in both FOTRAN and C++ in the files attached.

Using the makefile, I get the following error:

make -f MakeFile.MPI all -B

mpicc   -c cppwrapper.cpp -pthread -L/home/carlos/.local/lib -lcantera  -L/home/carlos/opt/sundials-intel/lib -lsundials_cvodes -lsundials_ida -lsundials_nvecserial -L/opt/intel/mkl/lib/intel64 -lmkl_rt -lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -liomp5 -L/usr/local/lib -lboost_system  -I/home/carlos/.local/include -I/home/carlos/opt/sundials-intel/include -I/usr/local/include 
mpif90  -g -O0  -o test cppwrapper.o fwrapper.f  -lc -lstdc++ -pthread -L/home/carlos/.local/lib -lcantera  -L/home/carlos/opt/sundials-intel/lib -lsundials_cvodes -lsundials_ida -lsundials_nvecserial -L/opt/intel/mkl/lib/intel64 -lmkl_rt -lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -liomp5 -L/usr/local/lib -lboost_system  
/usr/bin/ld: /home/carlos/.local/lib/libcantera.a(Methane.os): referencia sin definir al símbolo '__powr8i4'
/opt/intel/compilers_and_libraries_2016.3.210/linux/compiler/lib/intel64/libimf.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
MakeFile.MPI:22: error in the instructions for the object 'test'
make: *** [test] Error 1

The non-MPI version of these files compiles without problems (It uses OpenMP, see the pragma in the C++ code). That indicates me that I've correctly loaded all the environment variables. 

I suspect that the error is due to the fact that there are 2 versions of the same library. The one used to compile fwrapper.f has MPI and the other non-MPI is the one used for Cantera.

I compiled both files separately using the "-c" option to generate only ".o" files. The compilation was successful. There was a warning that told me that the files were not linked.

¿Why is the linker failing?

Thank you very much for your help

Regards,
Carlos


cppwrapper.cpp
fwrapper.f
MakeFile.MPI

Ray Speth

unread,
Oct 2, 2016, 2:14:22 PM10/2/16
to Cantera Users' Group
Carlos,

I think the missing symbols come from libraries that the C/C++ compiler normally links automatically, but are not included when linking as a Fortran program. This is, for instance, why you need to have '-lstdc++' on the link line, while this would never be needed if you were using the C++ compiler to link. I don't know what library contains the symbol '__powr8i4'. Presumably it's one of the ones included with the Intel C++ compiler or the MKL. Some googling suggests that this might be in the library 'libmmd'.

Regards,
Ray
Reply all
Reply to author
Forward
0 new messages