A library usually has its own exception base class and builds with hidden symbol visibility. Two settings make generated code fit.
Export the symbols
$EXPORT MYLIB_EXPORT
$INCLUDE "mylib/visibility.hh"
Every generated class and free-function declaration gets MYLIB_EXPORT in front of it. Built with -fvisibility=hidden (CMake: CXX_VISIBILITY_PRESET hidden), the library exports exactly those — and a program linking it finds them. Without $EXPORT that link fails with undefined references, which is what the test in the mstring repository checks.
Derive from the library's base
// mylib/Exception.hh
class MYLIB_EXPORT Exception : public std::exception
{
public:
virtual std::string whatStr( ) const noexcept = 0;
char const *what( ) const noexcept override; // calls whatStr()
};
$EXCEPTION ENABLE NOPREFIX NOPOSTFIX
$EXCEPTION INHERITED PUBLIC Exception
$EXCEPTION OVERRIDE whatStr
OVERRIDE whatStr makes each generated exception implement std::string whatStr( ) const noexcept override instead of its own What() / what() — the base stays in charge.
Build it
Generate at build time and install the generated header with the others:
mstring_generate(GENERATED Errors.msg OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated/mylib)
add_library(mylib SHARED src.cpp ${GENERATED})
target_include_directories(mylib PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/generated)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/generated/mylib/Errors.hh DESTINATION include/mylib)
With Conan, mstring is a tool_requires of the library only; the library's consumers get the generated header and never need mstring.
plugin's dsold does exactly this — see the dsold walkthrough.

