Linking a fortran module with Yade (CMakeLists.txt)

Asked by Deepak

Hello,

I am trying to link a fortran module which is called by a C++ code inside Yade and I am not sure how to compile it properly with CMake (looks like CMake doesn't compile the fortran source)

I modified the trunk/CMakeLists.txt as :

project(Yade C CXX Fortran)
set(CMAKE_Fortran_COMPILER "mpif90")
set(CMAKE_CXX_COMPILER "mpicxx")
set(CMAKE_C_COMPILER "mpicc")
....
FIND_PACKAGE(MPI)

I put the fortran source in the trunk/py folder along with the C++ functions (implemented in _utils.hpp and_utils.cpp) and compilation proceeds without any errors. However when I start yade I get an undefined symbol error which looks this :

 undefined symbol: __coupler_MOD_hello (coupler fortran module name, and hello name of function in fortran)

This is because the fortran module has not been linked during compilation. My question is how can I link fortran sources for compilation.

Thanks and Regards,
Deepak

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Bruno Chareyre
Solved:
Last query:
Last reply:
Revision history for this message
Deepak (deepak-kn1990) said :
#1

P.S : for a simple case involving 1 .cpp and 1 .f90 source, I had used a CMakeLists.txt like this:

project(Appli C CXX Fortran)
cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_Fortran_COMPILER "mpif90")
set(CMAKE_CXX_COMPILER "mpicxx")
find_package(MPI)
add_executable(appli cfort.cpp fortmodule.f90)
target_link_libraries(appli)

and compiling manually by hand I do it this way :

mpicxx -c cfort.cpp
mpif90 -c fortmodule.f90
mpicxx -o appli cfort.o fortmodule.o -lgfortran -lmpi_mpifh -lmpi_cxx

thanks.

Revision history for this message
Best Bruno Chareyre (bruno-chareyre) said :
#2

Hi Deepak, I'm not sure the cmake process is very flexible in this situation but it should be possible to simply pass the link via the gcc flags, something like
cmake -DCMAKE_CXX_FLAGS=-lYourLib
(or maybe another flag will do)
Cheers
Bruno

Revision history for this message
Deepak (deepak-kn1990) said :
#3

Hello Bruno,

Thanks for your advice, I have compiled it modules as a shared lib and linked it!

Thanks and Regards,
Deepak

Revision history for this message
Deepak (deepak-kn1990) said :
#4

Thanks Bruno Chareyre, that solved my question.