如何防止cmake剥离创建的共享库 [英] how to prevent cmake from stripping the created shared library

查看:123
本文介绍了如何防止cmake剥离创建的共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调试器中运行可执行文件时,我看不到共享库的任何有意义的堆栈跟踪信息-而是函数的地址和共享库的路径。

When running the executable in the debugger, I don't see any meaningful stacktrace for the shared library -- but only the address of the function and the path of the shared library.

这适用于cmake版本3.7.2。

This applies to cmake version 3.7.2.

推荐答案


  • CMake不剥离默认情况下,您的调试符号。

  • 您需要使用适当的调试选项来编译共享库,例如

    • CMake does not strip your debug symbols by default.
    • You need to compile your shared libs with proper debug options, e.g.

      cmake -DCMAKE_BUILD_TYPE=Debug ..
      


    • 或者您可以修改 CMakeLists.txt 以添加调试标志。

      set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
      set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall")
      


    • 编辑

      CMake是一个构建脚本工具,它本身不会对二进制文件进行剥离,但是您可以要求它提供帮助如果需要,可以使用此功能。在此处查看我的其他帖子: Android NDK CMake构建工具链中的** strip **命令的路径变量

      CMake is a build scripting tool, itself does not do stripping on your binary, but you can ask it to help with this if you want. See my other post here: Android NDK path variable for **strip** command in CMake build tool chain

      如果您想让CMake剥离调试符号,则下面的行将剥离符号。

      Below lines will do symbol stripping if you want to let CMake to strip your debug symbols.

      add_custom_command(TARGET ${SHARED_LIBRARY_NAME} POST_BUILD
                  COMMAND "<path-to-your-bin>/strip" -g -S -d --strip-debug --verbose
                  "<path-to-your-lib>/lib${SHARED_LIBRARY_NAME}.so"
                  COMMENT "strip debug symbols done on final binary.")
      

      对于警告,您可以选择是否包含它,不是真的很重要。

      For the warnings, you can choose to have it or not, doesn't really matter.

      回到问题并进一步澄清,为了拥有调试符号,您需要在 DEBUG RelWithDebInfo 构建类型,方法是在cmake命令下面键入。

      Get back to the question and clarify further, in order to have debug symbols, you need to build your binary in DEBUG or RelWithDebInfo build type by typing below cmake command.

      cmake -DCMAKE_BUILD_TYPE=Debug ..
      

      cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
      

      如果要构建C源代码(不是我假设的cpp),则可以检查相应的 CMAKE_C_FLAGS

      If you are building C source code (not the cpp which I assumed), then you can check the corresponding CMAKE_C_FLAGS.

      从此处查看正式文档: https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html

      See the official document from here: https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html

      这篇关于如何防止cmake剥离创建的共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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