Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8386625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:59:34+00:00 2026-06-09T17:59:34+00:00

I have a C++ library which I’m trying to get running on Mac OS

  • 0

I have a C++ library which I’m trying to get running on Mac OS X with Clang. The library consists of a DLL and a Unit-Test executable. It compiles fine with GCC and MSVC, with GCC, I use the following settings:

  • The library is compiled with -fvisibility=hidden
  • All exposed classes are explicitly marked as __attribute__(visibility("default"))
  • The library has some exception classes, derived from std::runtime_error. All such classes are marked for default visibility. There is a root class LibraryException from which more specific exceptions are derived.
  • On GCC, I use -std=c++0x, with clang, both the library and the unit test executable is built with -stdlib=libc++ -std=c++11

On Mac OS X, the unit test framework now fails, because exceptions are of the wrong type. I.e. a test like this fails:

// bla.foo () throws CustomException, which is derived from LibraryException
TEST_THROWS (bla.foo (), CustomException)

// This works however
TEST_THROWS (bla.foo (), LibraryException)

I verified that the typeinfo and vtable of my custom exception classes is exported using nm -g library.dylib | c++filt -p -i. This seems to be the case for all exceptions … what the heck is going on here? I have tried to debug on the of the errors, and I see how the correct type is being thrown in the library and yet the same type cannot be caught in the unit test executable. Is there something special required with Clang to get this working? I’m using the latest googletest framework from SVN for testing.

A small test program exhibits the same problem:

try {
    funcThatThrowsCustomExceptionFromLibraryDylib ();
} catch (CustomException& e) {
    // doesn't get here
} catch (LibraryException& e) {
    // does get here
    // after demangle, this prints CustomException
    // Can cast down to CustomException and access the fields as well
    std::cout << typeid (e).name () << "\n";
}

It also fails for instance when a boost::lexical_cast exception is thrown from the Library.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:59:35+00:00Added an answer on June 9, 2026 at 5:59 pm

    Here is the correct solution:

    When applying the visibility attribute, it must be applied both when the library is compiled as well when it is consumed. Otherwise, the client will not see the classes. For boost::lexical_cast, this means you have to use

     #pragma GCC visibility push(default)
     #include <boost/lexical_cast.hpp>
     #pragma GCC visibility pop
    

    until they get it fixed in the library by adding a __attribute((visibility("default"))) to the exception (as of Boost 1.50, the attribute is present, but it seems that the support for Clang is not there yet). When using it in a header in the library, so it can be properly caught in the client code. This #pragma also works with Clang.

    The fact that specifying a throw () destructor helped was some luck, but it’s definitely not the right fix.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .dll library which exports a function in the following format: _Java_folder1_folder2_folder3_JavaClassName_javamethodname@16
I have a library which is compiled in VS 2005 and I am trying
I have implemented software which have a DLL library which contains a set of
I have an external library which has a method which performs a long running
I have an external library which has a method which performs a long running
I have a C# library which has System.Data.SQLite as a reference, and an executable
I have this library called BASS which is an audio library which I'm going
I have a library which has a basic class which is used extensively by
If i have a library which is compiled in .NET 4 and reference it
I have a c-library which I use in gcc. The library has the extension

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.