Skip to content

Something is wrong with the configuration macros when static linking #169

Closed
@pdimov

Description

@pdimov

When using static libraries, a variety of things don't work. On macOS, any attempted use fails with

In file included from /Users/runner/work/stacktrace/boost-root/libs/stacktrace/test/cmake_install_test/main.cpp:6:
In file included from /Users/runner/.local/include/boost/stacktrace/stacktrace.hpp:27:
In file included from /Users/runner/.local/include/boost/stacktrace/safe_dump_to.hpp:[22](https://github.com/boostorg/stacktrace/actions/runs/9615275190/job/26522048559#step:8:23)1:
/Users/runner/.local/include/boost/stacktrace/detail/collect_unwind.ipp:33:2: error: "Boost.Stacktrace requires `_Unwind_Backtrace` function. Define `_GNU_SOURCE` macro or `BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED` if _Unwind_Backtrace is available without `_GNU_SOURCE`."
#error "Boost.Stacktrace requires `_Unwind_Backtrace` function. Define `_GNU_SOURCE` macro or `BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED` if _Unwind_Backtrace is available without `_GNU_SOURCE`."
 ^

whereas shared libraries work. Under Linux and Windows, things "work", but for instance test_noop.cpp fails when linked with boost_stacktrace_noop statically, even though it succeeds when linked dynamically.

I believe this is caused by the library incorrectly setting its configuration macros. safe_dump_to.hpp includes the implementation .ipp files when BOOST_STACKTRACE_LINK is not defined:

#if !defined(BOOST_STACKTRACE_LINK) || defined(BOOST_STACKTRACE_INTERNAL_BUILD_LIBS)

BOOST_STACKTRACE_LINK is a nonstandard macro that is set in push_options.h when the standard one BOOST_STACKTRACE_DYN_LINK is defined:

# define BOOST_STACKTRACE_LINK

It is, however, not set when building static libraries (whose standard configuration macro is BOOST_STACKTRACE_STATIC_LINK, which CMakeLists.txt sets.)

Consequently, the library "thinks" it's in header only mode when static libraries are used, which is wrong and causes the issues above.

I don't know what the correct fix is; maybe BOOST_STACKTRACE_LINK needs to be defined when BOOST_STACKTRACE_STATIC_LINK is set, maybe something else. But currently things aren't right. (I think that this also presents problems on MinGW and Cygwin.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions