简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM