简体   繁体   中英

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. I'm building in Windows using Cygwin. 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. As yock stated, you need to set up a cross-compiler targeted for the Android operating system.

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. Just including the header files you want isn't enough to tell GCC to target an arch, you need a 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.

You can get the (correct) cross compiler that runs in Windows here . There is also a C/C++ compiler included in the Android NDK, which you can find here

You should use androis gcc version to compile your source. Using ndk-build and the NDK build tools.

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命令。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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