使用Android NDK编译Boost时assert.h冲突

assert.h conflict when compiling Boost with Android NDK

本文关键字:assert 冲突 Boost Android NDK 编译 使用      更新时间:2023-10-16

当尝试使用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本身提供的函数之间存在某种冲突,但我该如何解决?

谢谢。

头文件有#define宏,它封装了整个头文件的内容。在你的源代码中,你可以更喜欢取消定义你不需要的标题。

例如,如果Boost头文件具有#define Boost_SSERT_HPP,而NDK具有ANDROID_ASSERT_H,则在源中,可以使用#undef Boost_ASSERT_HPP来取消Boost相关头的定义。