简体   繁体   English

Android NDK标准头文件编译错误

[英]Android NDK Standard Header File Compile Errors

I am having some issues using the Android NDK (for first time) and compiling a simple C file. 我在使用Android NDK(第一次)并编译一个简单的C文件时遇到了一些问题。 The odd thing is that I get these compile errors on the standard header files themselves which I would expect no errors to be generated within these unless I didn't include all of the includes files. 奇怪的是,我在标准头文件本身上遇到了这些编译错误,除非没有包含所有包含文件,否则我希望这些错误不会在其中生成任何错误。 Here is what I did... 这是我做的...

javac myJavaFile.java
javah -d location/include location.MyJavaFile

This runs fine and creates the appropriate header file. 这样可以正常运行并创建适当的头文件。 I then run the android ndk C compiler on my associated C file but I get errors in the standard header files. 然后,我在关联的C文件上运行android ndk C编译器,但在标准头文件中出现错误。 My command is as follows (shortened absolute paths for readability) 我的命令如下(缩短了可读性的绝对路径)

...android-ndk-r11c-windows-x86_64\android-ndk-r11c\toolchains\x86_64-4.9\prebuilt\
windows-x86_64\bin\x86_64-linux-android-gcc.exe -I ...jdk1.6.0_35\include -I 
...android-ndk-r11c-windows-x86_64\android-ndk-r11c\platforms\android-18\arch-x86\usr\
include -I ...jdk1.6.0_35\include\win32 -c myCFile.c

I get the following generated errors when doing this: 这样做时,我收到以下生成的错误:

C:\Program Files\Java\jdk1.6.0_35\include/jni.h:621:25: error: expected ')'     before '*' token
 jcharArray (JNICALL *NewCharArray)
                     ^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:623:26: error: expected ')' before '*' token
 jshortArray (JNICALL *NewShortArray)
                      ^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:625:24: error: expected ')' before '*' token
 jintArray (JNICALL *NewIntArray)
                    ^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:627:25: error: expected ')' before '*' token
 jlongArray (JNICALL *NewLongArray)
                     ^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:629:26: error: expected ')' before '*' token
 jfloatArray (JNICALL *NewFloatArray)
                      ^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:631:27: error: expected ')' before '*' token
 jdoubleArray (JNICALL *NewDoubleArray)
                       ^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:634:25: error: expected ')' before '*' token
 jboolean * (JNICALL *GetBooleanArrayElements)
                     ^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:636:22: error: expected ')' before '*' token
 jbyte * (JNICALL *GetByteArrayElements)
                  ^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:638:22: error: expected ')' before '*' token
 jchar * (JNICALL *GetCharArrayElements)
                  ^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:640:23: error: expected ')' before '*' token
 jshort * (JNICALL *GetShortArrayElements)
                   ^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:642:21: error: expected ')' before '*' token
 jint * (JNICALL *GetIntArrayElements)
                 ^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:644:22: error: expected ')' before '*' token
 jlong * (JNICALL *GetLongArrayElements)
                  ^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:646:23: error: expected ')' before '*' token
 jfloat * (JNICALL *GetFloatArrayElements)
                   ^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:648:24: error: expected ')' before '*' token
 jdouble * (JNICALL *GetDoubleArrayElements)
                    ^
C:\Program Files\Java\jdk1.6.0_35\include/jni.h:651:19: error: expected ')' before '*' token
 void (JNICALL *ReleaseBooleanArrayElements)
               ^
    C:\Program Files\Java\jdk1.6.0_35\include/jni.h:653:19: error: expected ')' before '*' token
 void (JNICALL *ReleaseByteArrayElements)
 ^
    C:\Program Files\Java\jdk1.6.0_35\include\win32/jni_md.h:11:19: error: expected declaration specifiers before '__declspec'
 #define JNIEXPORT __declspec(dllexport)

So what am I doing wrong here? 那我在做什么错呢? Wrong compiler? 错误的编译器? Include file, jni.h does exist. 包含文件,jni.h确实存在。 I'm running on Windows 7 Pro 64 bit. 我在Windows 7 Pro 64位上运行。

It looks like you're including the Windows JDK version of jni.h. 您似乎包括了Windows JDK版本的jni.h。 You should be including the version that is shipped with the NDK for your target platform. 您应该包括目标平台NDK附带的版本。 For instance, if you're targeting Gingerbread on an ARM device, use platforms/android-9/arch/arm/usr/include/jni.h. 例如,如果要在ARM设备上定位Gingerbread,请使用platform / android-9 / arch / arm / usr / include / jni.h。

But the fact that you're invoking the C compiler directly makes me think you might be in for a rough time. 但是,您直接调用C编译器的事实使我认为您可能会陷入困境。 The NDK is sort of a finicky toolchain. NDK是一种挑剔的工具链。 The code it emits is intended to be dynamically linked into a Dalvik executable, so it needs to have its gcc options set just right or it won't load. 它发出的代码旨在动态链接到Dalvik可执行文件中,因此需要正确设置其gcc选项,否则将无法加载。 It is not a normal Linux toolchain. 它不是普通的Linux工具链。 There's a (possibly apocryphal) story that for a long time only one person at Google understood the NDK build system, and every NDK release had to be built on his desktop or it wouldn't work. 有一个(可能是伪造的)故事,很长一段时间以来,只有Google的一个人才能理解NDK构建系统,并且每个NDK版本都必须在他的桌面上构建,否则将无法正常工作。 ;-) ;-)

I'd advise you to start by using the ndk-build script or the Android Studio gradle plugin , which is currently (April 2016) still labeled "experimental." 我建议您首先使用ndk-build脚本或Android Studio gradle插件 (目前(2016年4月)仍标记为“实验性”)开始。 Once you understand how the toolchain works, then you can switch to a make system more to your liking. 一旦了解了工具链的工作原理,就可以根据自己的喜好切换到make系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM