使用时出现构建问题与 Android ndk
我有一个简单的文件 stlTest2.cpp
,如下所示:
#include <jni.h>
#include <cmath>
bool isnan (void);
我正在移植的某些代码中有更复杂的内容。我的问题是这样的。为什么在 NDK 之外使用 GCC 构建时会起作用,但在使用 NDK 时却不起作用?它给出的错误是这样的:
jni/stlTest2.cpp:6: error: expected unqualified-id before 'sizeof'
jni/stlTest2.cpp:6: error: expected ')' before 'sizeof'
造成这种情况的直接原因是 math.h
(通过
包含)将 isnan
定义为宏。为什么 ndk 外部的构建不包含 math.h
中的 #define
,但这是?如果我注释掉代码中的包含内容,一切都很好,但这是不可接受的,因为这个问题会重复出现......很多。
I have a simple file stlTest2.cpp
like this:
#include <jni.h>
#include <cmath>
bool isnan (void);
There is something more complicated in some code I am porting. My question is this. Why would this work when building using GCC outside of the NDK, but not with using the NDK? There error it gives is this:
jni/stlTest2.cpp:6: error: expected unqualified-id before 'sizeof'
jni/stlTest2.cpp:6: error: expected ')' before 'sizeof'
The immediate reason for this is that math.h
(included via <cmath>
) defines isnan
as a macro. Why is the build outside of the ndk not including the #define
from math.h
, but this is? If I comment out the includes in the code, all is fine, but that is not acceptable as this problem repeats itself.... a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
isnan
宏是在 C99 中添加的。在 C++11 中,它被添加为std
命名空间中的函数,并为float
和double
和long double
重载。 code> (因此典型的
标头,例如您的非 NDK GCC 可能正在使用的标头,可能具有如下所示的内容:),但显然 NDK 尚未收到备忘录,并且仍然提供C99宏作为一种方便。 (
isnan
从来都不是 C++ 中的宏,但在 TR1 添加std::tr1::isnan
之前,并没有真正的 C++ 替代方案,因此多个 C++ 编译器提供了C99 宏。)您是否需要能够使用编译器提供的
isnan
或std::isnan
?如果没有,那么您可以将其更改为:(
对于任何其他有问题的宏也类似,前提是您不需要它们)。
The
isnan
macro was added in C99. In C++11 it was added as a function in thestd
namespace, overloaded forfloat
anddouble
andlong double
(so a typical<cmath>
header, such as your non-NDK GCC is probably using, might have something like this:), but apparently the NDK hasn't gotten the memo, and is still providing the C99 macro as a convenience. (
isnan
was never a macro in C++, but before TR1 addedstd::tr1::isnan
, there wasn't really a C++ alternative, so multiple C++ compilers provided the C99 macro.)Do you need to be able to use the compiler-provided
isnan
orstd::isnan
? If not, then you can just change this:to this:
(and similarly for any other problematic macros, provided you don't need them).
在 $ndk\sources\cxx-stl\gnu-libstdc++\libs\armeabi\include\bits\c++config.h (将armeabi更改为适当的值)中,将其更改为:
然后
再次清理并构建您的项目。
In $ndk\sources\cxx-stl\gnu-libstdc++\libs\armeabi\include\bits\c++config.h (change armeabi to whatever is appropriate) change this:
to
Then clean and build your project again.