2

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.

This applies to cmake version 3.7.2.

  • Does using a [`CMAKE_BUILD_TYPE`](https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html) of `RelWithDebInfo` work? – Justin Dec 18 '18 at 22:26
  • Which generator are you using? Makefile? – Cinder Biscuits Dec 18 '18 at 22:30
  • `I don't see any meaningful stacktrace` this is not an issue with cmake (build generator), but with your build (the thing that is run after cmake). Compile with debugging symbols enabled - use CMAKE_BUILD_TYPE=debug or add debug compiler options to your CMAKE_?_FLAGS. – KamilCuk Dec 18 '18 at 22:38
  • Possible duplicate of [What are CMAKE\_BUILD\_TYPE: Debug, Release, RelWithDebInfo and MinSizeRel?](https://stackoverflow.com/q/48754619/608639) and [CMake build mode RelWithDebInfo](https://stackoverflow.com/q/1239845/608639) – jww Dec 19 '18 at 02:35
  • It sounds like the shared library wasn't created with debug information or the debug shared library isn't the one being loaded at runtime. You should give more details on how you invoked CMake and the generator. Can you post a minimal example that reproduces the issue. – fdk1342 Dec 19 '18 at 16:54

1 Answers1

0
  • 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 ..
    
  • Or you can modify your CMakeLists.txt to add the debug flags.

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

Edit

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

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.

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 ..

or

cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..

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

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

shizhen
  • 12,251
  • 9
  • 52
  • 88
  • CMake doesn't strip debug symbols at all. That's the wrong way to add flags as it only adds it for C++ debug and release modes ignoring every other configuration that could be built, you would add it via `target_compile_options` and it wouldn't necessarily be the gcc option for enabling warnings. – fdk1342 Dec 20 '18 at 19:08