View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015872CMakeCMakepublic2015-12-06 23:392016-05-02 08:30
ReporterBen Matthews 
Assigned To 
StatusclosedResolutionno change required 
Platformx86_64OSLinuxOS VersionVarious
Product VersionCMake 3.3.2 
Target VersionFixed in Version 
Summary0015872: Programs with Fortran entry point (but calls into C) don't link correctly using Intel or PGI compilers
DescriptionCMake always seems to link mixed language programs using the C++ compiler. Intel and PGI link libcrt, which wants to have a main(). Programs with a Fortran entry point typically won't have main(). Setting the linker_language property doesn't seem to make a difference.

Using the GNU compilers, CMake still uses the C++ compiler, but it gets the libraries right and everything works as expected.
Steps To Reproducegit clone [^]
cd cmake_f90_entry_bug
mkdir build
cd build
CC=icc CXX=icpc FC=ifort cmake ../

Scanning dependencies of target testprog
[ 50%] Building Fortran object CMakeFiles/testprog.dir/test.f90.o
[100%] Linking CXX executable testprog
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
CMakeFiles/testprog.dir/build.make:94: recipe for target 'testprog' failed
make[2]: *** [testprog] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/testprog.dir/all' failed
make[1]: *** [CMakeFiles/testprog.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Additional InformationNote that the example code is a bit of a simplified/contrived example. It will work fine if you remove the HAS_CXX property, but real cases also incorporate C/C++ modules and require that libc/libstdc++ be present.

icc -V
Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version Build 20120731
Copyright (C) 1985-2012 Intel Corporation. All rights reserved.
TagsNo tags attached.
Attached Files


Brad King (manager)
2015-12-07 08:41

The HAS_CXX property is documented as obsolete and equivalent to setting LINKER_LANGUAGE to "CXX". Just don't set HAS_CXX. If there are C++ sources in the target CMake will know it needs to add the C++ runtime libraries and such even when using the Fortran linker.
Robert Maynard (manager)
2016-05-02 08:30

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2015-12-06 23:39 Ben Matthews New Issue
2015-12-07 05:17 tgallagher Note Added: 0039957
2015-12-07 05:19 tgallagher Note Edited: 0039957
2015-12-07 05:25 tgallagher Note Deleted: 0039957
2015-12-07 08:41 Brad King Note Added: 0039958
2015-12-07 08:41 Brad King Status new => resolved
2015-12-07 08:41 Brad King Resolution open => no change required
2016-05-02 08:30 Robert Maynard Note Added: 0040979
2016-05-02 08:30 Robert Maynard Status resolved => closed

Copyright © 2000 - 2018 MantisBT Team