在Mavericks下编译OpenNI2时glh_linear出现错误的解决方法

今天尝试在Maverick上编译OpenNI2,编译的时候始终显示这样一堆错误:

c++ -x c++ -c -arch i386 -arch x86_64 -msse3 -DMACOS -Wall -O2 -DNDEBUG -I../../../Include -I../../../ThirdParty/PSCommon/XnLib/Include -I../../../ThirdParty/GL/  -fPIC -fvisibility=hidden -o ../../../Bin/Intermediate/x64-Release/NiViewer/NiViewer.o NiViewer.cpp  
In file included from NiViewer.cpp:75:  
In file included from ../../../ThirdParty/GL/glh/glh_glut2.h:61:  
In file included from ../../../ThirdParty/GL/glh/glh_convenience.h:52:  
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/iostream:38:  
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/ios:216:  
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/__locale:18:  
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/mutex:176:  
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/__mutex_base:16:  
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/system_error:383:29: error: expected member name or ';' after declaration
      specifiers
    virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT;
    ~~~~~~~~~~~~            ^
../../../ThirdParty/GL/glh/glh_linear.h:80:36: note: expanded from macro 'equivalent'
#define     equivalent(a,b)     (((a < b + GLH_EPSILON) && (a > b - GLH_EPSILON)) ? true : false)
                                   ^

其错误主要是说:../../../ThirdParty/GL/glh/glh_linear.h:80:35: note: expanded from macro 'equivalent'

从源码追溯了一下,发现在glh\_linear.h中的宏equivalent/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr//lib/c++/v1/system_error中的一个函数重名了。(或者说是跟llvm::sys::fs::equivalent冲突了)

解决方法很简单,就是把glh\_linear.h中与equivalent相关的内容改个名字就行。

后来上网查了查,发现已经有人遇到了一模一样的问题:Compiling OpenNI2-2.0.0.30 on mac with clang fails: macro equivalent() in ThirdParty/GL/glh/glh_linear.h clashes with llvm::sys::fs::equivalent #52

甚至有人发布了一个patch文件。在原帖中有

这个问题已经在OpenNI2的develop版中解决了

Friskit

继续阅读此作者的更多文章