去C++可以做什么当两个 Linux 第三方库在其枚举中使用相同的名称时
我正在 Linux 上工作,使用第三方 C 和一堆第三方 C++ 代码,我正在编写我的 C++ 代码,但无法编译,因为编译器抱怨两次:
错误:冲突的声明 XXXX(我的变量姓名) 错误:XXXX 具有先前的十进制
XXXX 是第三方库的两个库内的两个不同枚举集中的枚举成员。
存在类似问题的案例不止一处。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该将 C 库标头包含在单独的命名空间中。
这样,由于外部 C 代码不使用命名空间,程序仍将正确链接,但名称(在 C++ 级别)将不再与其他 C++ 库发生冲突。
You should include the C library header in a separate namespace.
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.