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










_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to