我不知道您描述的问题的令人满意的解决方案,但我只是想分享一种处理这种情况的方法。时不时地(必须)使用一些特别令人讨厌的标题,它重新定义了英语的很大一部分。Python.h
想到了X11 标头。我最终做的——而且效果很好——是(通常在我注意到破损之后)我将第 3 方标题包装在我自己的标题中并处理那里的丑陋。
例如,在使用 Ruby 解释器的项目中,我通常不包含ruby.h
目录,而是包含一个ourruby.h
看起来像这样的文件:
#ifndef RUBY_OURRUBY_H
#define RUBY_OURRUBY_H
// In Ruby 1.9.1, win32.h includes window.h and then redefines some macros
// which causes warnings. We don't care about those (we cannot fix them).
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable:4005)
#endif
#include <ruby.h>
#ifdef _MSC_VER
# pragma warning(pop)
#endif
// In Ruby 1.8.7.330, win32.h defines various macros which break other code
#ifdef read
# undef read
#endif
#ifdef close
# undef close
#endif
#ifdef unlink
# undef unlink
#endif
// ...
#endif // !defined(RUBY_OURRUBY_H)
这样,我就不必记住某些标头并不完全是命名空间干净的事实。