Using GCC’s link-time optimization with static linked libraries
Here is an MCVE CMake project that reproduces the problem: $ ls -R hellow hellow: CMakeLists.txt hello.c libhello.c $ cat hellow/CMakeLists.txt cmake_minimum_required (VERSION 2.6) project (hellow) SET(CMAKE_C_FLAGS “${CMAKE_C_FLAGS} -flto”) SET(CMAKE_EXE_LINKER_FLAGS “${CMAKE_EXE_LINKER_FLAGS} -flto”) #SET(CMAKE_AR “gcc-ar”) #SET(CMAKE_C_ARCHIVE_CREATE “<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>”) #SET(CMAKE_C_ARCHIVE_FINISH true) add_library(hello STATIC libhello.c) add_executable(hellow hello.c) target_link_libraries(hellow hello) add_dependencies(hellow hello) $ cat hellow/hello.c extern … Read more