Using C ++ 11 compared to GCC 4.8 by default causes communication error with private inheritance and raise

Preamble

Working with a large piece of code, which I can’t break into MCVE right now , so I’ll do my best.


Problem

I am working with a large project that compiled as a static library, libfoo.a . A separate project, bar , references this library. The “offensive” snippet in libfoo as follows:

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

Both libfoo and bar extensive use of . bar must be compiled with -std=c++11 because of the C ++ 11 features it uses, but libfoo can be compiled with minimal parameters (i.e. -std=c++0x default compiler options used by GCC v4.8 , which looks like -std=gnu++03 ).

When I try to bind bar with -std=c++0x GCC, the default compiled libfoo.a fails with a long warning with a name that reduces to:

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

When I rebuild libfoo.a with -std=c++11 , this problem no longer occurs.


Work longer

I compared the output of libfoo.a via , and in both cases the corresponding characters were present. I also went through the Cxx11Abi compatibility docs , and it doesn't seem like this compiler option should “break” the compatibility.


Question

What is the cause of this linker problem?

+5
source share
1 answer

As MartinBonner notes, this is due to namespace changes in the types used in function prototypes. The only solutions were to either compile via -std=c++11 or rewrite large amounts of code to have an extra layer of “abstraction” around the type.

0
source

Source: https://habr.com/ru/post/1270277/


All Articles