如何为条带文件配置 cmake

How to config cmake for strip file(如何为条带文件配置 cmake)

本文介绍了如何为条带文件配置 cmake的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在发布模式下使用 cmake 时,我有以下二进制文件:

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-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=485ac09b0a3aa879f88b7f5db6c00ea8d8e1eaf6, not stripped

我想剥离二进制文件.我怎么能以干净的方式告诉 cmake 将 -s 选项添加到我的编译器中以使其被剥离?

I want the binary to be stripped. How can I say to cmake in a clean way to add the -s option to my compiler to make it stripped?

为什么默认发布模式没有剥离我的二进制文件?

Why did the Default Release mode not strip my binary?

推荐答案

最简单的方法是修改CFLAGS或CXXFLAGS(取决于C或C++代码)

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")

但是如果你不想改变你的构建系统,还有一个技巧(找出在上面放置的确切位置可能会很棘手).您可以将 strip 作为独立应用程序使用,例如:

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.

这篇关于如何为条带文件配置 cmake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何为条带文件配置 cmake

基础教程推荐