简体   繁体   English

Android NDK C #ifndef 问题

[英]Android NDK C #ifndef problems

I am using the NDK-r6 on Windows and want to compile a simple C program for testing purposes.我在 Windows 上使用 NDK-r6 并想编译一个简单的C程序用于测试目的。 Just compiling a C console program is not this easy, but I got the needed options.仅仅编译一个C控制台程序并不容易,但我得到了所需的选项。 The command line I use is (in cygwin):我使用的命令行是(在 cygwin 中):

 /cygdrive/f/android/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-gcc
-fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__
-D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__  -Wno-psabi -march=armv5te
-mtune=xscale -msoft-float -mthumb -Os  -funroll-all-loops -fomit-frame-pointer
-fno-strict-aliasing -finline-limit=64 -IF:/android_ws/stkeys/jni -DANDROID  
-Wa,--noexecstack -O3 -DNDEBUG -g -Wl,
-rpath-link=/android/android-ndk-r6/platforms/android-5/arch-arm/usr/lib 
-L/android/android-ndk-r6/platforms/android-5/arch-arm/usr/lib -nostdlib
/android/android-ndk-r6/platforms/android-5/arch-arm/usr/lib/crtbegin_dynamic.o 
-lc -IF:/android/android-ndk-r6/platforms/android-5/arch-arm/usr/include
F:/android_ws/stkeys/jni/stkeys.c F:/android_ws/stkeys/jni/sha1.c
-o F:/android_ws/stkeys/jni/stkeys

One hell of a commandline, but it works.一个地狱般的命令行,但它有效。 The problem is, that this code breaks:问题是,这段代码中断了:

#ifndef uint32_t
typedef unsigned int uint32_t;
#endif

#ifndef uint8_t
typedef unsigned char uint8_t;
#endif

This are the errors:这是错误:

In file included from F:/android_ws/stkeys/jni/stkeys.c:44:
F:/android_ws/stkeys/jni/sha1.h:23: error: redefinition of typedef 'uint32_t'
F:/android/android-ndk-r6/platforms/android-5/arch-arm/usr/include/stdint.h:53:
note: previous declaration of 'uint32_t' was here
F:/android_ws/stkeys/jni/sha1.h:27: error: redefinition of typedef 'uint8_t'
F:/android/android-ndk-r6/platforms/android-5/arch-arm/usr/include/stdint.h:49:
note: previous declaration of 'uint8_t' was here

I got it to compile by commenting out the definitions of uint32_t etc. in stdint.h, but this can't be the solution.我通过在 stdint.h 中注释掉 uint32_t 等的定义来编译它,但这不是解决方案。 Is this a bug in the NDK, or am I doing something wrong here?这是 NDK 中的错误,还是我在这里做错了什么?

It obviously isn't expecting stdint.h to be included.显然不希望包含 stdint.h 。 Don't know why.不知道为什么。

The test #ifndef only works for testing if something has been #define d.测试#ifndef仅适用于测试是否已被#define d。 There is no way to do typedef s conditionally.没有办法有条件地执行typedef

I would rather hack the application code than the standard headers.我宁愿破解应用程序代码而不是标准头文件。 :-) :-)

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

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