jeudi 27 juillet 2017

Using C++11 versus C++0x causes link error with private inheritance and boost

Preamble

Working with a large piece of code that I can't currently break down into an MCVE, so I'll my best.


Problem

I'm working with a large project that is compiled as a static library, libfoo.a. A separate project, bar, links against that library. The "offending" snippet in libfoo is as follows:

class Base {
public:
    void foo(){}
    void bar(){}
};

class Derived : private Base {
public:
    using Base::foo;
};

Both libfoo and bar make extensive use of . bar has to be compiled with -std=c++11 due to C++11 features it makes use of, but libfoo can be compiled with minimal options (i.e. -std=c++0x the default compiler options used by GCC v4.8).

When I attempt to link bar using a -std=c++0x compile libfoo.a, it fails with a lengthy, name-mangled warning, which reduces to:

Undefined reference to Base::Derived::foo()

When I re-build libfoo.a with -std=c++11, this issue no longer occurs.


Work So Far

I compared the output of libfoo.a via and in both cases, the appropriate symbols were present. I've also gone through the Cxx11Abi compatibility documents, and it doesn't appear that this compiler setting should "break" compatibility.


Question

What is the cause of this linker issue?

Aucun commentaire:

Enregistrer un commentaire