I'm trying to define a header-only library which gets included in multiple object-files. Everything works if I define all the class's methods in-line,
// lib.hpp
class Foo {
void fn() { ... }
};
But a dependency loop with class Bar
requires I define Foo::fn
out of line.
// lib.hpp
class Foo {
void fn();
}
class Bar { ... }
void Foo::fn() { ... }
And I am suddenly getting multiple definitions of Foo::fn
(as expected).
My question is how to define the method out-of-line while making the visibility local to each object file (as it was when it was in-line). If this were a function, I would slap a static
in front, but that seems to only further incense my compiler.
- I tried using
static
, no luck. - I tried using
__attribute__ ((visibility ("hidden")))
, no luck. - This is not a duplicate of How to avoid multiple definition linking error?, because that is a name-conflict (different names and different definitions), which can be resolved with a
namespace
. I have a "false" name conflict, because I want the names be "hidden" rather than both available under disambiguous identifiers. - This is not a duplicate of multiple definition error including c++ header file with inline code from multiple sources because my code is unique within one translation unit but is not between multiple object-files.