Using CheckFortranFunctionExists

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Using CheckFortranFunctionExists

Hugh Sorby

Hi All,

I'm trying to use CheckFortranFunctionExists​ to test for getarg which is failing on an Ubuntu 16.04 test machine and OS X test machine.  The test I have put together is provided below in text form.

The test for getarg fails, the executable 'bob' fails to link but the executable 'dave' links and runs as expected.

The error from 'bob' is

[ 75%] Linking Fortran executable bob
Undefined symbols for architecture x86_64:
  "_getarg_", referenced from:
      _MAIN__ in src.f.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[2]: *** [bob] Error 1
make[1]: *** [CMakeFiles/bob.dir/all] Error 2
make: *** [all] Error 2​

The files used in text form:

================== CMakeLists.txt =====================

cmake_minimum_required(VERSION 3.4)

project(getarg_prog VERSION 1.0.0 LANGUAGES Fortran)


check_fortran_function_exists(getarg HAVE_GETARG)

add_executable(bob src.f)

add_executable(dave dave.f)


=================== src.f =========================

      program TESTFortran
      external getarg
      call getarg()
      end program TESTFortran


======================== dave.f ==========================

       PROGRAM test_getarg
         INTEGER :: i
         CHARACTER(len=32) :: arg

         DO i = 1, iargc()
           CALL getarg(i, arg)
           WRITE (*,*) arg
         END DO


Can anyone explain why this is happening and how I would go about testing for the getarg function if I am doing it wrong.



Powered by

Please keep messages on-topic and check the CMake FAQ at:

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support:
CMake Consulting:
CMake Training Courses:

Visit other Kitware open-source projects at

Follow this link to subscribe/unsubscribe: