【问题标题】:Android NDK C #ifndef problemsAndroid NDK C #ifndef 问题
【发布时间】:2011-08-14 04:13:39
【问题描述】:

我在 Windows 上使用 NDK-r6,并想编译一个简单的 C 程序用于测试目的。 仅仅编译一个 C 控制台程序并不容易,但我得到了所需的选项。 我使用的命令行是(在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

一个地狱般的命令行,但它工作。问题是,这段代码坏了:

#ifndef uint32_t
typedef unsigned int uint32_t;
#endif

#ifndef uint8_t
typedef unsigned char uint8_t;
#endif

这是错误:

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

我通过在 stdint.h 中注释掉 uint32_t 等的定义来编译它,但这不是解决方案。 这是 NDK 中的错误,还是我在这里做错了什么?

【问题讨论】:

  • 这是我有代码的路径。它不是真正的 jni 代码。里面只有 stkeys.c sha1.c 和 sha1.h 文件

标签: android c android-ndk c-preprocessor conditional-compilation


【解决方案1】:

显然不希望包含 stdint.h。不知道为什么。

测试#ifndef 仅适用于测试某事物是否为#defined。没有办法有条件地做typedefs。

我宁愿破解应用程序代码而不是标准头文件。 :-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多