[CMake] How to find fortran library

Bill Hoffman bill.hoffman at kitware.com
Thu Dec 4 08:46:35 EST 2008


Javier Gonzalez wrote:
> Maik Beckmann wrote:
>> Am Mittwoch, 3. Dezember 2008 schrieb Javier Gonzalez:
>>   
>>> Hi all,
>>>
>>> I have a project that links to another project built with Fortran. My
>>> own project is a C++ project and I usually need to link against a
>>> fortran library of some sort to use the first one. I use gcc, so it
>>> usually is libgfortran or libg2c.
>>>
>>> Now my question is: if I enable Fortran, will there be a variable that
>>> tells me the location of the library I need to link to?
>>>     
>> No.  The compiler frontend (gfortran, g77, ...) makes the decision which 
>> system and compiler libraries have to be linked in.  
>>
>> If you or cmake link an fortran executable with 
>>   g77 -o myapp a.o b.o ..
>> libg2c will be linked in by g77.  When doing
>>   g77 -o myapp a.o b.o ..
>> libgfortran will be linked in by gfortran.
>>
>> The same is true for g++, which links in libstdc++ by default.
>>
>>   
>>> What I do at the moment is that I guess which library I need to link to
>>> based on the Fortran compiler's name and, since I use gcc, try to find
>>> it in the path given by 'gcc -print-search-dirs'. Is this the right way?
>>> I would expect that cmake defines a variable with this information
>>> somewhere.
>>>     
>> This is the right way.  Maybe an effort to write cmake module which handles 
>> this task is worthy.
>>
>> Best,
>>  -- Maik
>>
>>
>> _______________________________________________
>> CMake mailing list
>> CMake at cmake.org
>> http://www.cmake.org/mailman/listinfo/cmake
>>
>>   
> I see.
> 
> Later I saw Bill's message about the new release. One of the changes in
> 2.6.3 RC5 is:
> - Add FortranCInterface.cmake module to discover Fortran/C interfaces
> 
> I wonder if that is precisely what I was looking for so I will check it out.
> 
No not really.  That module figures out the name mangling scheme of the 
fortran compiler.   It does not figure out the run time libraries.

-Bill


More information about the CMake mailing list