为什么 cmake 生成带有 debug_info 的二进制文件而不是剥离
为什么 cmake 生成带有 debug_info 的二进制文件而不被删除?
这是我的 CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
# project name
project(c-program)
set(CMAKE_C_COMPILER "/usr/bin/gcc")
set(CMAKE_C_STANDARD "90")
set(CMAKE_C_STANDARD_REQUIRED true)
set(CMAKE_C_FLAGS "-ansi -Wall")
set(CMAKE_C_FLAGS_DEBUG "-g3 -ggdb3")
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
add_executable(c-program c-program.c)
我从项目根文件夹 $ cmake -S 构建
。 -B build/release -DCMAKE_BUILD_TYPE=Release
$ cmake --build build/release
运行时
$ file build/release/c-program
我得到
build/release/c-program:ELF 64 位 LSB 饼可执行文件,x86-64,版本 1 (SYSV),动态链接,解释器 /lib/ld-musl-x86_64.so.1,使用 debug_info,未剥离
我对调试/发布版本应该如何工作感到困惑,并且 cmake 教程指南或文档或其他在线内容中没有任何内容可以帮助我弄清楚为什么会发生这种情况
why is cmake producing a binary with debug_info and not stripped?
here is my CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
# project name
project(c-program)
set(CMAKE_C_COMPILER "/usr/bin/gcc")
set(CMAKE_C_STANDARD "90")
set(CMAKE_C_STANDARD_REQUIRED true)
set(CMAKE_C_FLAGS "-ansi -Wall")
set(CMAKE_C_FLAGS_DEBUG "-g3 -ggdb3")
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
add_executable(c-program c-program.c)
i build like this from the project root folder
$ cmake -S . -B build/release -DCMAKE_BUILD_TYPE=Release
$ cmake --build build/release
when running
$ file build/release/c-program
i get
build/release/c-program: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, with debug_info, not stripped
i am confused about how debug/release builds are supposed to work, and nothing in the cmake tutorial guides or docs or otherwise online is helping me figure out why this is happening
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
CMakeLists.txt
中设置标志存在一些问题,因此添加和使用工具链文件会有所帮助,并在工具链文件。此外,链接器正在添加调试信息。将-s
标志添加到 cmake 发布标志,并将-Wl,--strip-debug
添加到链接器标志是我正在寻找的,这是我的最终
CMakeLists .txt
和工具链
文件there are some issues with setting flags in
CMakeLists.txt
, so adding and using a toolchain file helped, and setting appropriateCMAKE_<LANG>_FLAGS_<CONFIG>_INIT
vars in the toolchain file. also, the linker is adding debug info. adding-s
flag to cmake release flags, and adding-Wl,--strip-debug
to linker flags is what i was looking forhere is my final
CMakeLists.txt
andtoolchain
files