I have a C ++ library that I am trying to run 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:
- Library compiled with
-fvisibility=hidden - All public classes are explicitly marked as
__attribute__(visibility("default")) - There are some exception classes in the library derived from
std::runtime_error . All such classes are marked for visibility by default. There is a root class LibraryException from which more specific exceptions are thrown. - In GCC, I use
-std=c++0x , with clang, and the library and unit test executable are built with -stdlib=libc++ -std=c++11
On Mac OS X, the unit test framework now fails because exceptions are of the wrong type. That is, such a test fails:
// bla.foo () throws CustomException, which is derived from LibraryException TEST_THROWS (bla.foo (), CustomException) // This works however TEST_THROWS (bla.foo (), LibraryException)
I checked that the typeinfo and vtable of my custom exception classes are exported using nm -g library.dylib | c++filt -p -i nm -g library.dylib | c++filt -p -i . It's like all exceptions ... what the hell is going on here? I tried to debug errors, and I see how the correct type is being created in the library, but the same type cannot be found in the unit test executable. Is there anything special for Clang to get this to work? I am using the latest googletest from SVN for testing.
A small test program shows the same problem:
try { funcThatThrowsCustomExceptionFromLibraryDylib (); } catch (CustomException& e) {
It also fails, for example, when the boost::lexical_cast exception is boost::lexical_cast from the Library.
source share