如何为条带文件配置 cmake

2023-10-17C/C++开发问题
0

本文介绍了如何为条带文件配置 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6