<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    <div class="moz-text-flowed" style="font-family: -moz-fixed;
      font-size: 14px;" lang="x-western">Hello,
      <br>
      <br>
      I ran into some trouble trying to link a mixed language
      Fortran/C++ program.
      <br>
      I used a CMakeLists.txt that looks about like this:
      <br>
      <br>
      # cmake version
      <br>
      cmake_minimum_required(VERSION 2.8)
      <br>
      <br>
      # name of the project
      <br>
      PROJECT(Q2P1)
      <br>
      <br>
      enable_language (Fortran)
      <br>
      <br>
      set(CMAKE_Fortran_COMPILER "mpif90")
      <br>
      <br>
      # add subdirectories
      <br>
      ADD_SUBDIRECTORY(CPLUSPLUS)
      <br>
      <br>
      SET(src_fortran ...)
      <br>
      <br>
      ADD_EXECUTABLE(Q2P1 ${src_fortran})
      <br>
      <br>
      target_link_libraries(Q2P1 CPLUSPLUSLibrary)
      <br>
      <br>
      <br>
      I invoke cmake like this "CC=mpicc CXX=mpic++ cmake
      -DCMAKE_Fortran_COMPILER=mpif90"
      <br>
      and a working Makefile is produced, the code compiles with no
      error and the CPLUSPLUSLibrary is created.
      <br>
      The linking process exits with an error <i class="moz-txt-slash"><span
          class="moz-txt-tag">/</span>usr/lib<span class="moz-txt-tag">/</span></i>../lib64/crt1.o:
      In function `_start': <i class="moz-txt-slash"><span
          class="moz-txt-tag">/</span>usr/src/packages/BUILD/glibc-2.9/csu<span
          class="moz-txt-tag">/</span></i>../sysdeps/x86_64/elf/start.S:109:
      undefined reference to `main'
      <br>
      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
      <br>
      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
      <br>
      cmake to use mpif90 to link the program? I tried setting
      CMAKE_LINKER to mpif90, but that did not change anything...
      <br>
      <br>
      Thanks,
      <br>
      Raphael
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
      <br>
    </div>
  </body>
</html>