gpt4 book ai didi

android-ndk - 使用arm-linux-androideabi-gcc编译对象时出现问题

转载 作者:行者123 更新时间:2023-12-04 00:55:31 29 4
gpt4 key购买 nike

背景

  • OSX是操作系统
  • R8 NDK

  • 我正在尝试使用Android GCC编译器编译以下类...
    #include <stdint.h>
    int main (void){
    return 0;
    }

    我使用以下命令执行...
    un@un:~/Development/Code/OpenGL$ ~/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/arm-linux-androideabi-gcc hello.c -o hello

    我知道了
    In file included from hello.c:1:0:
    /Users/un/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/include/stdint.h:3:26: fatal error: stdint.h: No such file or directory
    compilation terminated.

    因此,由于缺乏gcc知识(但具备一定的Google能力),我找到了并尝试...
    un@un:~/Development/Code/OpenGL$ ~/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/arm-linux-androideabi-gcc hello.c -o hello -ffreestanding

    我得到...
    /Users/un/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtbegin_dynamic.o: No such file or directory
    /Users/un/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtend_android.o: No such file or directory
    /Users/un/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lc
    /Users/un/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot find -ldl
    collect2: ld returned 1 exit status

    有人可以帮我解决我做错的事情吗?我是否缺少链接或其他内容?不能选择Android.mk。

    更新这也不起作用...
    arm-linux-androideabi-gcc hello.c --sysroot=~/Development/Android/android-ndk-r8c/platforms/android-9/arch-arm
    /Users/jackiegleason/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtbegin_dynamic.o: No such file or directory
    /Users/jackiegleason/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtend_android.o: No such file or directory
    /Users/jackiegleason/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lc
    /Users/jackiegleason/Development/Android/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: error: cannot find -ldl
    collect2: ld returned 1 exit status

    最佳答案

    您必须告诉GCC在哪里可以找到Android系统文件和 header 。可以使用:

  • ndk-build和带有Android.mkBUILD_EXECUTABLE
  • --sysroot GCC选项

  • [1]
    LOCAL_PATH := $(call my-dir)

    include $(CLEAR_VARS)

    LOCAL_MODULE := foo
    LOCAL_SRC_FILES := foo.c

    include $(BUILD_EXECUTABLE)

    [2]
    # Change `android-9` with the level you target
    /path/to/android-ndk-r8c/toolchains/arm-linux-androideabi-4.6/prebuilt\
    /darwin-x86/bin/arm-linux-androideabi-gcc\
    --sysroot /path/to/android-ndk-r8c/platforms/android-9/arch-arm/\
    foo.c -o foo

    # Or generate a ready-to-use standalone toolchain (better)
    /path/to/android-ndk-r8c/build/tools/make-standalone-toolchain.sh \
    --platform=android-9 \
    --install-dir=/tmp/my-android-toolchain

    export SYSROOT=/tmp/my-android-toolchain/sysroot

    /path/to/arm-linux-androideabi-gcc --sysroot $SYSROOT foo.c -o foo

    关于android-ndk - 使用arm-linux-androideabi-gcc编译对象时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14307611/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com