Re-using a static library containing objective-C symbols in a shared library results in 'Class X is implemented in both Y and Z'

Viewed 31

Let's say I have a static library, let's call it LibraryWithObjectiveC. It's a C++ library, but for some platform specific things, I'm forced to also have some objective-C wrapper classes in there because Apple doesn't allow that functionality to be used with plain C or C++.

Now, this static library is used in executable, which, among other things also allows loading of external shared libraries with dlopen. They implement a COM-like interface, so let's call them COMLibrary. Some of these libraries also need the functionality provided by LibraryWithObjectiveC, and because they are designed to also work elsewhere, they thus need to link against LibraryWithObjectiveC themselves.

This leads to a bunch of warnings printed whenever the library is opened with dlopen. The warnings are something like this:

objc[xxxxxx]: Class X is implemented in both and . One of the two will be used. Which one is undefined.

Now, this obviously doesn't lead to any harm, since the symbols are exactly the same, but since the executable also has some command-line functionality it would be nice not to have these warning messages show up.

I have tried the following:

  • make the objective-C symbols hidden, this, it seems, is not possible for objective-c classes
  • changing stderr from my program, this does not stop warnings from dlopen

The only solution I could think of is to make LibraryWithObjectiveC a shared library, but there are reasons why this is not a preferred solution. Is there another way to get the loader to recognize that these are, in fact, the same symbols, or to at least not complain about it?

0 Answers
Related