[CMake] Mixing C/CPP and Fortran

Kyle Horne horne.kyle at gmail.com
Tue May 26 13:12:13 EDT 2009


On Tue, 26 May 2009 18:01:17 +0100
Alin M Elena <alinm.elena at googlemail.com> wrote:

> Hi All,
> 
> 
> I try to mix some C and Fortran (I know not such a good idea).
> 
> Anyhow I create a project and then use cmake to manage the build. (see attach)
> C is the main language, if I may say so, It links.
> 
> I get a linking error
> Linking C executable bin/testme
> /usr/bin/cmake -E cmake_link_script CMakeFiles/testme.dir/link.txt --verbose=1
> /usr/bin/gcc    -fPIC CMakeFiles/testme.dir/source/main.c.o  -o bin/testme -
> rdynamic lib/libhello.a
> lib/libhello.a(libhello.f90.o): In function `hello':
> libhello.f90:(.text+0x43): undefined reference to `_gfortran_st_write'
> libhello.f90:(.text+0x59): undefined reference to 
> `_gfortran_transfer_character'
> libhello.f90:(.text+0x71): undefined reference to `_gfortran_transfer_integer'
> libhello.f90:(.text+0x7d): undefined reference to `_gfortran_st_write_done'
> collect2: ld returned 1 exit status
> make[2]: *** [bin/testme] Error 1
> make[2]: Leaving directory `/home/alin/playground/mixCFortran/build'
> make[1]: *** [CMakeFiles/testme.dir/all] Error 2
> make[1]: Leaving directory `/home/alin/playground/mixCFortran/build'
> make: *** [all] Error 2
> 
> 
> The problem is very easy solvable by just linking against the fortran runtime 
> libs (/usr/lib64/libgfortran.so) in this case (gnu compilers).
> 
> My question is. Shouldn't cmake handle this internally, so the user does not 
> bother about?
> 
> regards,
> 
> Alin
> 
> -- 
>  ______________________________________________________________________
>  "If the Universities will not study useless subjects, who will?"
>                              G. F. FitzGerald, Nature, 45/46, 392 (1892)
>  ______________________________________________________________________
>  Mr  Alin M ELENA
>  Irish Centre for High-End Computing -- www.ichec.ie
>  The Design Tower, Trinity Technology & Enterprise Campus
>  Grand Canal Quay,  Dublin 2, Ireland
>  Tel:   +353 (0) 1 5241608 ext 29
>  Fax: +353 (0) 1 7645845
>  http://alin.elenaworld.net
>  alin.elena at ichec.ie
>  alinm.elena at gmail.com
>  ______________________________________________________________________
> 
> 


I don't think that it is desirable to have cmake automatically link in this case.  It looks like libhello.a is build from at least some fortran, thus causing the requirement for libgfortran, but how whould cmake know what to do?  Would it keep track of the fact the fortran was used to build libhello.a and then automatically append -lgfortran to any program which also links to libhello.a?  It may be better for the developers to remember the dependency and handle it themselves, even though that is more work for us. I'm not sure that cmake would know what libraries need to be linked when using more exotic fortran compilers(PGI, intel, absoft, nag, salford, etc).  Does it cause linking errors when libhello is compiled as a shared library too?



-- 
Kyle Horne <horne.kyle at gmail.com>


More information about the CMake mailing list