[CMake] linking mixed language executable; cmake choosing wrong compiler

Mitchell, John A jamitch at sandia.gov
Mon Jan 9 15:44:08 EST 2012


Hi,

I am trying to link a fortran/c++ executable.  main() is in the fortran file.  cmake is choosing to "Link CXX executable" rather than fortran executable?

Based upon my current CMakeLists.txt file,  cmake is choosing the wrong linker.

I can in fact cut and paste the cmake link line and replace 'mpicxx' with the correct compiler/linker ('mpif77') and it works just fine.

Here is the relevant CMakeLists.txt piece; main is in the file demo_cf_pointer.F90; I_Fortran is a c++ library;  I am using the intel compilers.

# CMakeLists.txt file
add_executable(demo_cf_pointer demo_cf_pointer.F90)
target_link_libraries(demo_cf_pointer I_Fortran -lstdc++)



Here is the output from the linker;  It is using my mpicxx compiler; Also note that the link line contains demo_cf_pointer.F90.o which indicates to me that it successfully found the mpif77 compiler that I am using.  I know it is because I can re-use this entire command with mpicxx replace with mpif77 to produce a valid executable.


CMAKE OUTPUT
Linking CXX executable demo_cf_pointer
cd /ascldap/users/jamitch/pditi_projects/pditi.build/i_fortran/demo && /projects/sierra/linux/install/cmake/2.8.1/bin/cmake -E cmake_link_script CMakeFiles/demo_cf_pointer.dir/link.txt --verbose=1
/ascldap/users/jamitch/pditi_projects/TPL/mpich2-1.4.1p1_installed/bin/mpicxx   -cxx=icpc -mkl -O0 -g -Wall   CMakeFiles/demo_cf_pointer.dir/demo_cf_pointer.F90.o  -o demo_cf_pointer -rdynamic -L/ascldap/users/jamitch/pditi_projects/TPL/trilinos_dev.installed/lib -L/ascldap/users/jamitch/pditi_projects/TPL/vtk-5.8-installed/lib/vtk-5.8 -L/ascldap/users/jamitch/pditi_projects/TPL/boost_1_48_0_installed/lib ../libI_Fortran.a -lstdc++ -lifport -lifcore -lintlc -Wl,-rpath,/ascldap/users/jamitch/pditi_projects/TPL/trilinos_dev.installed/lib:/ascldap/users/jamitch/pditi_projects/TPL/vtk-5.8-installed/lib/vtk-5.8:/ascldap/users/jamitch/pditi_projects/TPL/boost_1_48_0_installed/lib
/usr/local/intel/parallel_studio_XE/composerxe-2011.4.191/compiler/lib/intel64/libimf.so: warning: warning: feupdateenv is not implemented and will always fail
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
make[2]: *** [i_fortran/demo/demo_cf_pointer] Error 1


Thanks,
John


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120109/f3b7515d/attachment.htm>


More information about the CMake mailing list