boostorg / stacktrace

C++ library for storing and printing backtraces.
https://boost.org/libs/stacktrace
422 stars 69 forks source link

B2: `<visibility>hidden` as a requirement #146

Closed JBouwer closed 7 months ago

JBouwer commented 9 months ago

From build/Jamfile.v2:

project
  : source-location .
  : requirements
    [ requires cxx11_rvalue_references ]
    <visibility>hidden
  ;

Is there a reason why <visibility>hidden is a requirement?

i.e. Won't default-build be more suitable?

project
  : source-location .
  : requirements
    [ requires cxx11_rvalue_references ]
  : default-build
    <visibility>hidden
  ;

Thus allowing linking to the various libraries via b2; E.g.

lib MyTestingLib
    : # Sources
      ...
      /boost/stacktrace//boost_stacktrace_noop/<link>static/<visibility>global
      ...
    : # Requirements
      ...
    : # Default Build
        <link>shared
    : # Usage Requirements
        <define>BOOST_STACKTRACE_LINK
        <link>shared:<define>BOOST_STACKTRACE_DYN_LINK
    ;

Currently a target like the above fail to link with "Undefined symbols ...".

JBouwer commented 9 months ago

A workaround to achieve the above can be to:

  1. Create a static library from the desired StackTrace backend library.
  2. Link that into the destination library:

i.e.

# Intermediary Static Library
lib Boost_StackTrace
    : # Sources
        Boost_StackTrace.cpp

        # /boost/stacktrace//boost_stacktrace_noop
        /boost/stacktrace//boost_stacktrace_basic
        # ...
    : # Build Requirements
        <link>static
    : # Default Build
    : # Usage Requirements
    ;

# Destination Dynamic Library
lib MyTestingLib
    : # Sources
      ...
      Boost_StackTrace
      ...
    : # Requirements
      ...
    : # Default Build
        <link>shared
    : # Usage Requirements
        <link>shared:<define>BOOST_STACKTRACE_LINK
        <link>shared:<define>BOOST_STACKTRACE_DYN_LINK
    ;

and with Boost_StackTrace.cpp being just:

#include <boost/stacktrace.hpp>
apolukhin commented 7 months ago

Many thanks for the bugreport and fix hints!