How to config cmake for strip file(如何为条带文件配置 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
基础教程推荐
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- CString 到 char* 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
