user553514
user553514

Reputation: 227

What to do in C++ when two Linux third-party libraries are using the same names in their enumerations

I am working on Linux and using a third party C, and bunch of third party C++ code, and I am writing my C++ code and I can't compile because the compiler complains two times as such :

error: conflicting decalarations XXXX (my variable name) error: XXXX has a previous decalratoin

XXXX is an enumeration member in two different enumeration sets within the two libraries of the third party libraries.

There are more than one cases that have the similar problem.

Upvotes: 2

Views: 556

Answers (1)

C. K. Young
C. K. Young

Reputation: 223213

You should include the C library header in a separate namespace.

namespace foo {
    #include <foo.h>
}

This way, because external C code does not use namespaces, the program will still link properly, but the names will (at the C++ level) not collide with your other C++ libraries any more.

Upvotes: 6

Related Questions