[从CMake帮助列表无耻地跨贴]
我正在尽可能静态地创建二进制文件。 我有一个Fortran代码,它具有X11和quadmath依赖项,并且我遇到了许多问题(也许每个问题应该是不同的问题?):
My variables are currently
set(CMAKE_LIBRARY_PATH /usr/X11/lib /usr/X11/include/X11 ${CMAKE_LIBRARY_PATH}) find_package(X11 REQUIRED) find_library(X11 NAMES X11.a PATHS /usr/X11/include/X11/ /usr/X11/lib) find_library(X11_Xaw_LIB NAMES Xaw Xaw /usr/X11/include/X11/ /usr/X11/lib ${X11_LIB_SEARCH_PATH}) find_library(Xaw Xaw7 PATHS ${X11_LIB_SEARCH_PATH}) set(CMAKE_LIBRARY_PATH /usr/lib/gcc/x86_64-linux-gnu/4.7 /usr/lib/gcc/x86_64-linux-gnu/4.7/x32 /usr/lib/gcc/x86_64-linux-gnu/4.7/32 ${CMAKE_LIBRARY_PATH}) find_library(quadmath NAMES quadmath.a) set(BUILD_SHARED_LIBS ON) set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) set(LINK_SEARCH_START_STATIC TRUE) set(LINK_SEARCH_END_STATIC TRUE) set(SHARED_LIBS OFF) set(STATIC_LIBS ON) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
if I comment out only
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
, then CMake compiles everything, but uses shared libraries for every program, even though I specify the location of.a
X11 libraries in myfind_library()
calls. I was expecting CMake to use the .a files where it could and then only use shared libraries - is there a way to force this behaviour?does anyone know yet of a fix for the bug described here: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46539; whereby gfortran seemingly can't statically link libquadmath? I tried the fix using gcc but I can't get CMake to recognise the libgfortran flag:
cmake -DCMAKE_Fortran_COMPILER=gcc -DCMAKE_Fortran_FLAGS=-gfortran
导致
-- The Fortran compiler identification is unknown
-- Check for working Fortran compiler: /usr/bin/gcc
-- Check for working Fortran compiler: /usr/bin/gcc -- broken
CMake Error at /usr/share/cmake-2.8/Modules/CMakeTestFortranCompiler.cmake:54 (message):
The Fortran compiler "/usr/bin/gcc" is not able to compile a simple test program.
然而,正如你可能已经注意到的那样,我设置了libquadmath.a的位置;当我构建一个不使用X11但使用quadmath的程序时,我使用
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
那么这个程序确实编译成功了(运行 ldd 会报告“不是动态可执行文件”)——这意味着 bug 已经被修复了吗?还是只是因为我在 CMake 中设置了位置才起作用?