Force CMake to use static libraries

前端 未结 2 801
眼角桃花
眼角桃花 2021-01-18 02:41

[Shamelessly cross-posted from the CMake help list]

I\'m trying to create binaries as statically as possible. The fortran code I\'ve got has got X11 and quadmath a

2条回答
  •  迷失自我
    2021-01-18 03:01

    I was having a similar problem. Turns out that cmake was implicitly linking against libgfortran and libquadmath. To fix this I put the following in my top level CMakeLists.txt:

    unset(CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES)
    

    I could then explicitly link again the libraries using:

    SET_TARGET_PROPERTIES(main_f PROPERTIES LINKER_LANGUAGE "C"
      LINK_FLAGS
      "/usr/local/Cellar/gcc/7.1.0/lib/gcc/7/libgfortran.a 
      /usr/local/Cellar/gcc/7.1.0/lib/gcc/7/libquadmath.a -lm -lgcc"
    )
    

    The static version of libgfortran is necessary because the shared library also depends on libquadmath. The added "-lm" and "-lgcc" bring in the system dynamic versions of these libraries. On a mac system, you would want to use the full path to your libm.a as well.

提交回复
热议问题