[CMake] Fortan and C++

Michael Wild themiwi at gmail.com
Sat Aug 22 08:03:12 EDT 2009


Hi Dominik

Concerning the flags: you should add the -no-multibyte-chars to the  
CMAKE_CXX_FLAGS variable. This will get prepended to all  
CMAKE_CXX_FLAGS_{RELEASE,DEBUG,...} flags, since you don't want this  
flag to be used for the Release configuration exclusively, but for all  
configurations.

Linking against ifcore using the C++ compiler only works if it is on  
the search path (probably by sourcing ifortvars.sh), otherwise you'll  
have to specify it's full path. I think, Intel recommends using the  
the Fortran compiler for linking instead, and passing it the -cxxlib  
and -nofor_main flags (those are the correct names now, I looked them  
up ;-)).

On Mac platforms there is another problem: By default the g++ compiler  
generates 32-bit code, while the Intel Fortran compiler generates 64- 
bit code (very annoying).

If you try to use FortranCInterface.cmake, be aware that it is quite  
buggy, as it doesn't pass the CMAKE_*_FLAGS to the try_compile calls.  
Further it doesn't ensure that the C language is enabled, altough it  
is calling try_compile on C code! I'll file a bug report with an  
attached patch for that.

All the best

Michael

On 22. Aug, 2009, at 13:35, Dominik Szczerba wrote:

> Here the report of my tests:
>
> Just ignorant approach (don't google):
>
> It works out of the box on linux with intel compilers 10.x. Just add  
> Fortran to the languages in the project signature and add STUFF.F90  
> to the source files. You need to link to ifcore library though.
>
> It does not work out of the box with the compilers 11.x. Here the  
> ignorant approach failed. The errors were like:
>
> -- Check for working CXX compiler: /usr/local/bin/icpc-11.0.083
> -- Check for working CXX compiler: /usr/local/bin/icpc-11.0.083 --  
> broken
> CMake Error at /usr/local/share/cmake-2.6/Modules/ 
> CMakeTestCXXCompiler.cmake:25 (MESSAGE):
>  The C++ compiler "/usr/local/bin/icpc-11.0.083" is not able to  
> compile a
>  simple test program.
>
>  It fails with the following output:
>
>   Change Dir: /home/domel/build/solve/CMakeFiles/CMakeTmp
>
> Checking by foot what the compilers at all say during compilations I  
> found:
>
> > icpc-11.0.083 -c test.cxx
> Catastrophic error: could not set locale "" to allow processing of  
> multibyte characters
>
> Googling reveals a bug in the compiler to be circumvented with  
> adding '-no-multibyte-chars' to the compiler switches. However,  
> adding this to my CMAKE_XXX_FLAGS_RELEASE (my CMAKE_BUILD_TYPE is  
> RELEASE) does not help. I must now either specify CMAKE_XXX_FLAGS  
> explicitly on the commandline or in the cache. Probably because  
> cmake uses default flags (CMAKE_XXX_FLAGS) for compiler checks, even  
> if CMAKE_BUILD_TYPE is explicitly set release/debug (as well as  
> corresponding release/debug flags).
>
> Maybe cmake should use compiler flags as defined by CMAKE_BUILD_TYPE  
> to check for compilers?
>
> - Dominik
>
>
>
> Dominik Szczerba wrote:
>> Michael,
>> Many thanks for the feedback.
>> What I am doing with a GNU makefile so far is compile just one file  
>> with the fortran compiler use C++ linker to link all object files  
>> as usual.
>> A comprehensive solution I would expect in cmake would be 1)  
>> nothing (.f90 file is understood) or something along the lines of  
>> setting the file properties (sort of 'to be compiler with' flag)...
>> - Dominik
>> Michael Wild wrote:
>>>
>>>
>>> On 21.08.2009, at 17:57, Dominik Szczerba <dominik at itis.ethz.ch>  
>>> wrote:
>>>
>>>> I want to compile one file with fortran compiler (intel) and  
>>>> link  with the rest of my project. Will the latest cmake allow to  
>>>> fully  cmakify such scenario?
>>> Hi Dominik
>>>
>>> If I remember correctly, you'll have to set the LINK_LANGUAGE  
>>> property  of your target to Fortran and then ensure that the  
>>> Fortran linker also  links against the C++ standard library. For  
>>> Intel this would be -stdc+ + (or some such). If you are creating  
>>> an executable, depending on  where your main-function is defined,  
>>> you might also need to tell the  linker to not add a Fortran main- 
>>> function, the flag is called - nofor_main if I remember correctly.  
>>> Otherwise the ifort man-page will  tell you :)
>>>
>>>
>>> HTH
>>>
>>> Michael
>
>
> -- 
> d o m i n i k   s z c z e r b a ,   p h d . . . . . . . . . . .
> c o m p u t a t i o n a l   l i f e   s c i e n c e   g r o u p
> . . . . . . . i t ' i s   r e s e a r c h   f o u n d a t i o n
> . . . . . . . . . . . . . . . . . . . . http://www.itis.ethz.ch
>



More information about the CMake mailing list