如何为条形文件配置cmake [英] How to config cmake for strip file

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

问题描述

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

  64位LSB可执行文件,x86-64,版本1(SYSV),动态链接,解释器/lib64/ld-linux-x86-64.so.2,用于GNU / Linux 2.6.32,BuildID [sha1] = 485ac09b0a3aa879f88b7f5db6c00ea8d8e1eaf6,未剥离

我希望二进制文件被剥离。
如何以一种干净的方式向cmake添加-s选项以使其被剥离?



为什么默认释放模式不是剥离我的二进制文件?

解决方案

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

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

但如果您不想更改构建系统,放在上面的线可能会很棘手)。您可以将strip作为独立应用程序使用,例如:

  strip -s a.out 

并在可执行文件准备好作为后期构建步骤发布后执行此操作。我发现这种方式更干净,然后干扰编译器标志。

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

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?

解决方案

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.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆