当尝试使用Android NDK使用Boost c ++库编译程序时,我收到以下类型的错误:
In file included from /home/afeder/android/0ad/jni/lib/boost/boost/assert.hpp:50,
from /home/afeder/android/0ad/jni/lib/boost/boost/random/linear_congruential.hpp:21,
from /home/afeder/android/0ad/jni/src/source/scriptinterface/ScriptInterface.h:34,
from /home/afeder/android/0ad/jni/src/source/ps/World.h:28,
from /home/afeder/android/0ad/jni/src/source/main.cpp:58:
/home/afeder/android/android-ndk-r7/platforms/android-5/arch-arm/usr/include/assert.h: At global scope:
/home/afeder/android/android-ndk-r7/platforms/android-5/arch-arm/usr/include/assert.h:63: warning: redundant redeclaration of 'void __assert(const char*, int, const char*)' in same scope
/home/afeder/android/android-ndk-r7/platforms/android-5/arch-arm/usr/include/assert.h:63: warning: previous declaration of 'void __assert(const char*, int, const char*)'
/home/afeder/android/android-ndk-r7/platforms/android-5/arch-arm/usr/include/assert.h:64: warning: redundant redeclaration of 'void __assert2(const char*, int, const char*, const char*)' in same scope
/home/afeder/android/android-ndk-r7/platforms/android-5/arch-arm/usr/include/assert.h:64: warning: previous declaration of 'void __assert2(const char*, int, const char*, const char*)'
显然,Boost提供的一组“断言”函数与NDK本身提供的函数之间存在某种冲突,但我该如何解决呢?
感谢。
答案 0 :(得分:1)
头文件有#define宏,它封装了整个头文件内容。在您的来源中,您可以更喜欢取消定义不需要的标题。
示例,如果Boost头文件具有#define BOOST_ASSERT_HPP且NDK具有ANDROID_ASSERT_H,则在源中可以使用#undef BOOST_ASSERT_HPP取消定义与Boost相关的头。