Skip to content

Stack is empty with -fno-exceptions on m2 macbook #161

@Ghost-LZW

Description

@Ghost-LZW

We can build this library without the -no-exceptions flag and then link it with a no-exceptions library. However, I found that without exception support, the stack will be empty. Here is an simple example.

cmake_minimum_required(VERSION 3.24...3.26)

project(test)
set(CMAKE_CXX_STANDARD 20)

include(FetchContent)
FetchContent_Declare(
  cpptrace
  GIT_REPOSITORY https://github.com/jeremy-rifkin/cpptrace.git
  GIT_TAG        v0.7.0 # <HASH or TAG>
)
FetchContent_MakeAvailable(cpptrace)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")

add_executable(my_target test.cc)

target_link_libraries(my_target cpptrace::cpptrace)

# Create a .dSYM file on macOS
if(APPLE)
  add_custom_command(
    TARGET my_target
    POST_BUILD
    COMMAND dsymutil $<TARGET_FILE:my_target>
  )
endif()
#include "cpptrace/cpptrace.hpp"

void test() {
  cpptrace::generate_trace().print();
}

int main() {
  test();
}

/*
Stack trace (most recent call first):
<empty trace>
*/

I test it on Apple M2 Pro macbook.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions