简体   繁体   English

使用cygwin for JNI编译C ++代码(Android NDK)

[英]Compiling C++ code with cygwin for JNI (Android NDK)

I'm trying to build a C++ file for using in my Android application over JNI. 我正在尝试构建一个C ++文件,以便通过JNI在我的Android应用程序中使用。 I'm building in Windows using Cygwin. 我正在使用Cygwin在Windows中构建。 I'm completely new to this and don't know what I am doing. 我对此完全陌生,不知道我在做什么。

Here's part of the output: 这是输出的一部分:

$ g++ -c test_wrap.cxx -I"C:\dev\android-ndk-r4b\build\platforms\android-4\arch-arm\usr\include" -I./include
In file included from C:/dev/android-ndk-r4b/build/platforms/android-4/arch-arm/usr/include/sys/_types.h:40,
                 from C:/dev/android-ndk-r4b/build/platforms/android-4/arch-arm/usr/include/stdint.h:32,
                 from C:/dev/android-ndk-r4b/build/platforms/android-4/arch-arm/usr/include/sys/types.h:34,
                 from C:/dev/android-ndk-r4b/build/platforms/android-4/arch-arm/usr/include/strings.h:42,
                 from C:/dev/android-ndk-r4b/build/platforms/android-4/arch-arm/usr/include/stdlib.h:42,
                 from test_wrap.cxx:160:
C:/dev/android-ndk-r4b/build/platforms/android-4/arch-arm/usr/include/machine/_types.h:44: error: conflicting declaration 'typedef long unsigned int size_t'/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/stddef.h:213: error: 'size_t' has a previous declaration as `typedef unsigned int size_t'
C:/dev/android-ndk-r4b/build/platforms/android-4/arch-arm/usr/include/machine/_types.h:44: error: declaration of `typedef long unsigned int size_t'/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/stddef.h:213: error: conflicts with previous declaration `typedef unsigned int size_t'
C:/dev/android-ndk-r4b/build/platforms/android-4/arch-arm/usr/include/machine/_types.h:44: error: declaration of `typedef long unsigned int size_t'/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/stddef.h:213: error: conflicts with previous declaration `typedef unsigned int size_t'
C:/dev/android-ndk-r4b/build/platforms/android-4/arch-arm/usr/include/machine/_types.h:46: error: conflicting declaration 'typedef long int ptrdiff_t'/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/stddef.h:151: error: 'ptrdiff_t' has a previous declaration as `typedef int ptrdiff_t'
C:/dev/android-ndk-r4b/build/platforms/android-4/arch-arm/usr/include/machine/_types.h:46: error: declaration of `typedef long int ptrdiff_t'/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/stddef.h:151: error: conflicts with previous declaration `typedef int ptrdiff_t'
C:/dev/android-ndk-r4b/build/platforms/android-4/arch-arm/usr/include/machine/_types.h:46: error: declaration of `typedef long int ptrdiff_t'/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/stddef.h:151: error: conflicts with previous declaration `typedef int ptrdiff_t'

Can you please give me a hand? 你能帮我一下吗?

Emmanuel 灵光

Applications built in the Cygwin environment assume that the application will execute on Windows with the Cygwin DLL available. Cygwin环境中构建的应用程序假定该应用程序将在Windows上使用Cygwin DLL可用时执行。 As yock stated, you need to set up a cross-compiler targeted for the Android operating system. 如yock所述,您需要设置一个针对Android操作系统的交叉编译器。

I'm not a C/C++ expert at all, but it seems to me that you're trying to compile for Arm with a compiler targeting i686. 我根本不是C / C ++专家,但是在我看来,您正在尝试使用针对i686的编译器为Arm进行编译。 Just including the header files you want isn't enough to tell GCC to target an arch, you need a cross compiler. 仅包含所需的头文件还不足以告诉GCC定位目标拱门,您需要一个交叉编译器。

http://wiki.osdev.org/GCC_Cross-Compiler http://wiki.osdev.org/GCC_Cross-Compiler

What you're trying to do with cygwin will not work for the reasons stated in David Harrris' answer. 由于戴维·哈里斯(David Harrris)的回答中所述的原因,您尝试使用Cygwin进行的操作无法正常工作。

You can get the (correct) cross compiler that runs in Windows here . 您可以在此处获取在Windows中运行的(正确)交叉编译器。 There is also a C/C++ compiler included in the Android NDK, which you can find here Android NDK中还包含一个C / C ++编译器,您可以在这里找到

You should use androis gcc version to compile your source. 您应该使用androis gcc版本来编译源代码。 Using ndk-build and the NDK build tools. 使用ndk-build和NDK生成工具。

If you just want to get rid of the 'already defined' error undefine it first to make sure your version is getting used: 如果您只是想摆脱“已经定义”的错误,请先取消定义它,以确保使用您的版本:

#undef size_t
#undef ptrdiff_t

答案很简单,就是创建一个Android.mk文件并使用ndk-build命令。

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

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