[CMake] fortran compiler failed to compile simple test program

Brad King brad.king at kitware.com
Tue Jun 16 08:46:14 EDT 2015


On 06/16/2015 01:21 AM, Ette, Anthony (CDS) wrote:
> what control does the user have over the compilation of the test program?

Very little.  The whole point is to test that the compiler works the way
CMake will invoke it in the generated build system.

> I.e. can I tell cmake to add -L (where to look for libraries)
> or -v (cf77 compiler verbose flag) when compiling the test program to
> avoid having to go to a full toolchain file and forcing the compiler?

If you use CMake 3.2 or higher then you can try a test project like this:

 cmake_minimum_required(VERSION 3.2)
 project(cf77test Fortran)

and run CMake as

 cmake . -DCMAKE_EXE_LINKER_FLAGS="-v"

to get more verbose output from the link step.

> I have found the -lrt is coming from /usr/lib/librt.so
[snip]
> If /usr/lib is in my path

It shouldn't matter if /usr/lib is in your PATH.  The linker does not
pay attention to PATH.  Linkers normally look in /usr/lib by default.

> rts1-4:/home/bzpl46/test2> cf77 -v -g test.f
> Linking executable: /usr/ccs/release/7.3/lib_ia32/ld ... -lrt ...

One can see that cf77 indeed adds -lrt to the link line itself.
So the question is: why does this work when invoked by hand but
not when CMake invokes it?

In the test project you sent in a sibling message, try this:

 $ cd CMakeFiles/CMakeTmp
 $ cat CMakeFiles/cmTryCompileExec4035725976.dir/link.txt
 /usr/ccs/bin/cf77       CMakeFiles/cmTryCompileExec4035725976.dir/testFortranCompiler.f.o  -o cmTryCompileExec4035725976 -rdynamic

Then run that command line by hand.  You can add -v to it too.
Note that the "4035725976" number will be different each time
so adapt to your local build tree accordingly.

-Brad



More information about the CMake mailing list