[CMake] FORTRAN name mangling

Michael Jackson mike.jackson at bluequartz.net
Mon Jan 11 12:58:09 EST 2016


I am trying to integrate a FORTRAN library into our C++ project. I have
used the following in our CMakeLists.txt file:

include(CMakeAddFortranSubdirectory)

cmake_add_fortran_subdirectory(src
  NO_EXTERNAL_INSTALL
  PROJECT EMSoftLib  # project name in toplevel CMakeLists.txt in lapack
  LIBRARIES EMSoftLib # target libraries created
  LINK_LIBRARIES blas lapack # link interface libraries
  LINK_LIBS EMSoftLib blas lapack
)

include(FortranCInterface)
FortranCInterface_HEADER(EMsoftLib_Mangling.h MACRO_NAMESPACE "EMSOFTLIB_")

So far so good.

In the FORTRAN code we have the following declaration for a subroutine we
want to use from the "C" side of things:

subroutine SingleEBSDPattern(ipar, fpar, EBSDpattern, quats, accum_e,
mLPNH, mLPSH) bind(c, name='SingleEBSDPattern')

In order to access that function we created the following header file:


#include "EMsoftLib_Mangling.h"
#ifdef __cplusplus
extern "C" {
#endif
void EMSOFTLIB_GLOBAL(SingleEBSDPattern, SINGLEEBSDPATTERN)
(size_t* ipar, float* fpar, float* EBSDpattern,
float* quats, float* accum_e, float* mLPNH, float* mLPSH);
#ifdef __cplusplus
}
#endif

and we call the function from our C code like the following:


SingleEBSDPattern_(ipar, fpar, ebsdPattern, quats, accum_e, mLPNH, mLPSH);

When we compile we get the following linker error:

MintDevVM:Build mdg$ make
[ 40%] Built target EMSoftLib
Scanning dependencies of target SingleEBSDPattern
[ 41%] Building CXX object
src/CMakeFiles/SingleEBSDPattern.dir/SingleEBSDPattern.cpp.o
[ 42%] Linking CXX executable ../Bin/SingleEBSDPattern
Undefined symbols for architecture x86_64:
  "_SingleEBSDPattern_", referenced from:
      _main in SingleEBSDPattern.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
make[2]: *** [Bin/SingleEBSDPattern] Error 1
make[1]: *** [src/CMakeFiles/SingleEBSDPattern.dir/all] Error 2
make: *** [all] Error 2

We can not seem to find any good examples of trying this sort of C->FORTRAN
interfacing with CMake besides http://www.kitware.com/blog/home/post/231

We are using gfortran 5.3 on OS X 10.10.5 with Xcode 7.2 tools.

Any insights would be most appreciated.

__________________________________________________
Mike Jackson                  mike.jackson at bluequartz.net
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160111/ec563400/attachment.html>


More information about the CMake mailing list