<div dir="ltr">I am trying to integrate a FORTRAN library into our C++ project. I have used the following in our CMakeLists.txt file:<div><br></div><div><div>include(CMakeAddFortranSubdirectory)</div></div><div><br></div><div><div>cmake_add_fortran_subdirectory(src</div><div>  NO_EXTERNAL_INSTALL</div><div>  PROJECT EMSoftLib  # project name in toplevel CMakeLists.txt in lapack</div><div>  LIBRARIES EMSoftLib # target libraries created</div><div>  LINK_LIBRARIES blas lapack # link interface libraries</div><div>  LINK_LIBS EMSoftLib blas lapack </div><div>)</div><div><div class="gmail_signature"><br></div><div class="gmail_signature"><div class="gmail_signature">include(FortranCInterface)</div><div class="gmail_signature">FortranCInterface_HEADER(EMsoftLib_Mangling.h MACRO_NAMESPACE "EMSOFTLIB_")</div><div class="gmail_signature"><br></div><div class="gmail_signature">So far so good. </div><div class="gmail_signature"><br></div><div class="gmail_signature">In the FORTRAN code we have the following declaration for a subroutine we want to use from the "C" side of things:</div><div class="gmail_signature"><br></div><div class="gmail_signature"><div class="gmail_signature">subroutine SingleEBSDPattern(ipar, fpar, EBSDpattern, quats, accum_e, mLPNH, mLPSH) bind(c, name='SingleEBSDPattern') </div><div><br></div><div>In order to access that function we created the following header file:</div><div><br></div><div><br></div><div><div>#include "EMsoftLib_Mangling.h"</div><div>#ifdef __cplusplus</div><div>extern "C" {</div><div>#endif</div><div>void EMSOFTLIB_GLOBAL(SingleEBSDPattern, SINGLEEBSDPATTERN)</div><div><span class="" style="white-space:pre">      </span>(size_t* ipar, float* fpar, float* EBSDpattern, </div><div><span class="" style="white-space:pre">          </span>float* quats, float* accum_e, float* mLPNH, float* mLPSH);</div><div>#ifdef __cplusplus</div><div>}</div><div>#endif</div></div><div><br></div><div>and we call the function from our C code like the following:</div><div><br></div><div><br></div><div><div>SingleEBSDPattern_(ipar, fpar, ebsdPattern, quats, accum_e, mLPNH, mLPSH);</div></div><div><br></div><div>When we compile we get the following linker error:</div><div><div><br></div><div>MintDevVM:Build mdg$ make</div><div>[ 40%] Built target EMSoftLib</div><div>Scanning dependencies of target SingleEBSDPattern</div><div>[ 41%] Building CXX object src/CMakeFiles/SingleEBSDPattern.dir/SingleEBSDPattern.cpp.o</div><div>[ 42%] Linking CXX executable ../Bin/SingleEBSDPattern</div><div>Undefined symbols for architecture x86_64:</div><div>  "_SingleEBSDPattern_", referenced from:</div><div>      _main in SingleEBSDPattern.cpp.o</div><div>ld: symbol(s) not found for architecture x86_64</div><div>clang: error: linker command failed with exit code 1 (use -v to see invocation)</div><div>make[2]: *** [Bin/SingleEBSDPattern] Error 1</div><div>make[1]: *** [src/CMakeFiles/SingleEBSDPattern.dir/all] Error 2</div><div>make: *** [all] Error 2</div></div><div><br></div><div>We can not seem to find any good examples of trying this sort of C->FORTRAN interfacing with CMake besides <a href="http://www.kitware.com/blog/home/post/231">http://www.kitware.com/blog/home/post/231</a></div><div><br></div><div>We are using gfortran 5.3 on OS X 10.10.5 with Xcode 7.2 tools.</div><div><br></div><div>Any insights would be most appreciated.</div><div><br></div><div>__________________________________________________<br></div></div></div><div class="gmail_signature">Mike Jackson                  <a href="mailto:mike.jackson@bluequartz.net" target="_blank">mike.jackson@bluequartz.net</a><br>BlueQuartz Software                    <a href="http://www.bluequartz.net" target="_blank">www.bluequartz.net</a><br>Principal Software Engineer                  Dayton, Ohio</div></div>
</div></div>