How to config cmake for strip file

后端 未结 2 928
甜味超标
甜味超标 2020-12-16 14:30

when I use cmake in Release mode I have the following binary:

64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linu         


        
相关标签:
2条回答
  • 2020-12-16 14:54

    Cleanest possible way is to modify CFLAGS or CXXFLAGS (depending on C or C++ code)

    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s")
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
    

    But there is one more hack if you do not want to change your build system (figuring out exact place where to put above lines might be tricky). You may just use strip as standalone application, like:

    strip -s a.out
    

    and do this after executable is ready to release as a post-build step. I found this way cleaner, then disturbing compiler flags.

    0 讨论(0)
  • 2020-12-16 14:56

    You can try

    set_target_properties(TARGET_NAME PROPERTIES LINK_FLAGS_RELEASE -s)
    
    0 讨论(0)
提交回复
热议问题