简体   繁体   English

第三方库中的宏冲突

[英]macro collisions in third party libraries

I'm using yojimbo - a networking library and spdlog - a logging library for a game that I'm working on.我正在使用yojimbo - 一个网络库和spdlog - 一个用于我正在开发的游戏的日志库。 When I try to compile a source file with headers of both yojimbo and spdlog, I get macro collisions resulting in lots of errors given by g++.当我尝试用 yojimbo 和 spdlog 的头文件编译源文件时,我遇到宏冲突,导致 g++ 给出很多错误。

Source files with either of the headers but not both compile ok.带有任何一个头文件但不能同时编译的源文件。

Is there a way to avoid macro collision in these third party libraries?有没有办法避免这些第三方库中的宏冲突?

Is there a way to avoid macro collision in these third party libraries?有没有办法避免这些第三方库中的宏冲突?

Yes.是的。 Simplest solution is to not include both headers that define the conflicting macros into same translation unit.最简单的解决方案是不将定义冲突宏的两个标头都包含到同一翻译单元中。 If that is not sufficient, then one potential solution is to undefine the conflicting macro after including first one.如果这还不够,那么一个可能的解决方案是在包含第一个宏之后取消定义冲突宏。 If you need both macros, then you can rewrite it with another name after the undefinition.如果您需要这两个宏,那么您可以在未定义后用另一个名称重写它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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