[CMake] anyone get create_test_sourcelist to work with fortran?

Ateljevich, Eli eli at water.ca.gov
Wed Jul 11 17:50:57 EDT 2012


Hi, I attempted to use create_test_sourcelist with a Fortran routines using the recipe from the cmake book. The CMakeLists.txt and fortran file are given below. The test *.cpp file is generated correctly, but the linker gives me this:
cd /home/eli/work/selfe_trunk/build/unittest/Hydro && /usr/local/dms/pkg/cmake/2.8.8/bin/cmake -E cmake_link_script CMakeFiles/Driver.dir/link.txt --verbose=1
/usr/bin/c++   -O3 -DNDEBUG    CMakeFiles/Driver.dir/driver.cpp.o CMakeFiles/Driver.dir/test_attempt.F90.o  -o ../../bin/Driver -rdynamic -L/usr/local/dms/pkg/hdf5/1.8.7-intel12.0-parallel/lib -lifport -lifcore -limf -lsvml -lipgo -lintlc -lpthread -lirc_s -ldl
CMakeFiles/Driver.dir/driver.cpp.o:(.data+0x8): undefined reference to `test_attempt(int, char**)'

I can't tell whether this is a Fortran-C interoperability issue or some sort of linking problem. In order to reduce the interoperability issue as a confounder, I manually altered the generated driver.cpp file my Fortran file to sequentially eliminate the double pointer, then all arguments and finally the return value. In each case  I got the same result: the symbol test_attempt is in test_attempt.F90.o but it is considered an undefined reference. Anyone know how to make it work? The solution should be of general interest since this is always the signature expected by create_test_sourcelist. I am on ifort with cmake 2.8.8.

Thanks -- Eli
**********
create_test_sourcelist(Tests
                       driver.cpp
                      test_attempt.F90)


add_executable(Driver ${Tests})

set(TestsToRun ${tests})
remove(TestsToRun driver.cpp)

foreach (test ${TestsToRun})
  get_filename_component(TName ${test} NAME_WE)
  add_test( ${TName} Driver ${TName})
endforeach()

***********
    function test_attempt(argc,argv) bind( c)
    use iso_c_binding
    integer(c_int) :: test_attempt
    integer(c_int)  :: argc
    type(c_ptr), dimension(1) :: argv
    print*, "Hello"
    test_attempt=0
    end function

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


More information about the CMake mailing list