[CMake] fortran flags in a c++ linked executable

Martin Apel martin.apel at simpack.de
Wed Apr 1 08:34:01 EDT 2009


James C. Sutherland wrote:
> Let me try this again.
>
> I have a f90 subroutine that performs file IO.  I would like to link
> that with a C++ driver.
>
> If I use a fortran driver, I am able to set the binary format via
>         set( CMAKE_Fortran_FLAGS "-fconvert=big-endian" )
> This results in file IO in big-endian format.
>
> When using the C++ driver, (linking with g++), I cannot get things
> working properly.  I have tried various compiler settings:
>
>         add_definitions( -Xlinker -fconvert=big-endian )          # links, but does
> not affect endian-ness
>         add_definitions( -Wl,-fconvert=big-endian )       # links, but does not
> affect endian-ness
>         add_definitions( -mbig-endian )  # does not work - link fails with
> unrecognized flag
>
> None of these result in an executable that properly handles big-endian
> file formats.
>
> The system I am compiling on is a little-endian system (intel Mac)
> with gfortran 4.4.0 and g++ 4.0.1.
>
>   
Hi James,

In general you can set linker options for your executable as follows:
  SET_TARGET_PROPERTIES(<ProgramName> PROPERTIES LINK_FLAGS
"-Wl,--fconvert=big-endian")

As far as I know, --fconvert=big-endian is a compiler option not a
linker option, so this will not work.

But I don't think that this will succeed, because the man page of
gfortran contains the following comment:
    -fconvert=conversion
           ....
           This option has an effect only when used in the main
program.  The "CONVERT" specifier and the GFORTRAN_CONVERT_UNIT
environment variable
           override the default specified by -fconvert.

As you probably don't have a Fortran main program, setting this option
will have no effect. In the end, you will have to find out, how to set
the conversion mode to use, if you don't have a Fortran main program. I
assume that you will have to explicitly select a library to link to your
program. Anyway, this is not a CMake issue.

Hope this helps,

Martin

____________
Virus checked by G DATA AntiVirus
Version: AVB 19.282 from 31.03.2009




More information about the CMake mailing list