[CMake] [CMake ] Specify linker for a mixed language Fortran/C++ application (linux)
Raphael Münster
Raphael.Muenster at math.uni-dortmund.de
Mon Jun 27 14:39:48 EDT 2011
Hello,
I ran into some trouble trying to link a mixed language Fortran/C++
program.
I used a CMakeLists.txt that looks about like this:
# cmake version
cmake_minimum_required(VERSION 2.8)
# name of the project
PROJECT(Q2P1)
enable_language (Fortran)
set(CMAKE_Fortran_COMPILER "mpif90")
# add subdirectories
ADD_SUBDIRECTORY(CPLUSPLUS)
SET(src_fortran ...)
ADD_EXECUTABLE(Q2P1 ${src_fortran})
target_link_libraries(Q2P1 CPLUSPLUSLibrary)
I invoke cmake like this "CC=mpicc CXX=mpic++ cmake
-DCMAKE_Fortran_COMPILER=mpif90"
and a working Makefile is produced, the code compiles with no error and
the CPLUSPLUSLibrary is created.
The linking process exits with an error /usr/lib/../lib64/crt1.o: In
function `_start':
/usr/src/packages/BUILD/glibc-2.9/csu/../sysdeps/x86_64/elf/start.S:109:
undefined reference to `main'
This happens because mpic++ is used to link, but the main program is
actually in the Fortran code. So the linking command looks about like
this mpic++ (list of object files) -o executable
The problem is solved when I just manually copy and paste the link
command that is printed on the command line and replace mpic++ with
mpif90... So the question is how can I tell
cmake to use mpif90 to link the program? I tried setting CMAKE_LINKER to
mpif90, but that did not change anything...
Thanks,
Raphael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110627/91e7c5cc/attachment-0001.htm>
More information about the CMake
mailing list