[CMake] [Fortran] Default flags for ifort on windows (and mxing C and Fortran)

Clinton Stimpson clinton at elemtech.com
Thu Jun 25 10:38:43 EDT 2009


On 06/25/2009 06:47 AM, Maik Beckmann wrote:
> Hello,
>
> Right now mixing Fortran and C compiled with respectively ifort and cl on
> windows doesn't work out of the box.  The reason for this is conflicting
> runtime libraries.
>
> The default for cl and ifort is, without any flags given, to use LIBC.lib.
> This the static single threaded version.
>
> CMake by default adds flags to the CMAKE_*_FLAGS to let cl use the MSVCRT.lib
> or MSVCRTD.lib (namely /MD or /MDd)
>
> These adjustments are not done for the ifort compiler (except for the
> "Release" build type where /MD is used :P ) so mixing sources causes LINK2005
> errors (already defined symbols).
>
> What about altering
>    SET (CMAKE_Fortran_FLAGS_INIT "/W1 /nologo /fpp")
>    SET (CMAKE_Fortran_FLAGS_DEBUG_INIT "/debug:full")
>    SET (CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "/O2 /D NDEBUG")
>    SET (CMAKE_Fortran_FLAGS_RELEASE_INIT "/MD /O1 /D NDEBUG")
>    SET (CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "/O1 /debug:full /D NDEBUG")
> to
>    SET (CMAKE_Fortran_FLAGS_INIT "/W1 /nologo /fpp /libs:dll /threads")
>    SET (CMAKE_Fortran_FLAGS_DEBUG_INIT "/debug:full /dbglibs")
>    SET (CMAKE_Fortran_FLAGS_MINSIZEREL_INIT "/O2 /D NDEBUG")
>    SET (CMAKE_Fortran_FLAGS_RELEASE_INIT "/MD /O1 /D NDEBUG")
>    SET (CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT "/O1 /debug:full /D NDEBUG")
> in Windows-ifort.cmake, The would let ifort behave the same as cl on windows,
> since
>     /threads /libs:dll<=>  /MD
> and
>    /threads /libs:dll /dbglibs<=>  /MDd
>
>    

If you add /libs:dll to all build types, then you can take /MD out of 
CMAKE_Fortran_FLAGS_RELEASE_INIT.
I had the same problem as you, and an almost identical patch sumbitted 
here: http://public.kitware.com/Bug/view.php?id=8744

Clint




More information about the CMake mailing list