servo / rust-stb-image

Rust bindings to the awesome stb_image library
Other
68 stars 34 forks source link

Error when compiling for Android #93

Closed tanis2000 closed 5 years ago

tanis2000 commented 5 years ago

When I compile a project that uses this crate I get an error while compiling the C source of this crate.

Here's the command I'm running, forcing the compiler to use as I'm trying to avoid having to build different Android toolchains based on the architecture:

CC=/Users/tanis/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc CXX=/Users/tanis/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++ AR=/Users/tanis/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ar SYSROOT=/Users/tanis/android-ndk/platforms/android-24/arch-arm/ cargo build --no-default-features --target armv7-linux-androideabi --lib

The result is the following error:

   Compiling stb_image v0.2.2
   Compiling curl-sys v0.4.16
   Compiling sdl2 v0.30.0 (https://github.com/Rust-SDL2/rust-sdl2.git?branch=unsafe-textures-feature#59a95913)
error: failed to run custom build command for `stb_image v0.2.2`
process didn't exit successfully: `/Users/tanis/Documents/minigame-rust/target/debug/build/stb_image-c7925d9f7ee898d4/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("armv7-linux-androideabi")
OPT_LEVEL = Some("0")
TARGET = Some("armv7-linux-androideabi")
HOST = Some("x86_64-apple-darwin")
TARGET = Some("armv7-linux-androideabi")
TARGET = Some("armv7-linux-androideabi")
HOST = Some("x86_64-apple-darwin")
CC_armv7-linux-androideabi = None
CC_armv7_linux_androideabi = None
TARGET_CC = None
CC = Some("/Users/tanis/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc")
TARGET = Some("armv7-linux-androideabi")
HOST = Some("x86_64-apple-darwin")
CFLAGS_armv7-linux-androideabi = None
CFLAGS_armv7_linux_androideabi = None
TARGET_CFLAGS = None
CFLAGS = None
DEBUG = Some("true")
running: "/Users/tanis/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-march=armv7-a" "-march=armv7-a" "-mfpu=vfpv3-d16" "-mfloat-abi=softfp" "-Wall" "-Wextra" "-o" "/Users/tanis/Documents/minigame-rust/target/armv7-linux-androideabi/debug/build/stb_image-9bbf328ed262afd5/out/src/stb_image.o" "-c" "src/stb_image.c"
cargo:warning=src/stb_image.c:390:19: fatal error: stdio.h: No such file or directory
cargo:warning= #include <stdio.h>
cargo:warning=                   ^
cargo:warning=compilation terminated.
exit code: 1

--- stderr
thread 'main' panicked at '

Internal error occurred: Command "/Users/tanis/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-march=armv7-a" "-march=armv7-a" "-mfpu=vfpv3-d16" "-mfloat-abi=softfp" "-Wall" "-Wextra" "-o" "/Users/tanis/Documents/minigame-rust/target/armv7-linux-androideabi/debug/build/stb_image-9bbf328ed262afd5/out/src/stb_image.o" "-c" "src/stb_image.c" with args "arm-linux-androideabi-gcc" did not execute successfully (status code exit code: 1).

', /Users/tanis/.cargo/registry/src/github.com-1ecc6299db9ec823/gcc-0.3.55/src/lib.rs:1672:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

warning: build failed, waiting for other jobs to finish...
error: build failed
jdm commented 5 years ago

I don't know that the SYSROOT variable is read by any part of the Rust native compilation tooling. I think you want to provide a --sysroot=/Users/tanis/android-ndk/platforms/android-24/arch-arm/ CFLAGS value instead.

tanis2000 commented 5 years ago

@jdm that worked a charm. I added the sysroot to CFLAGS and it did the trick. In case anyone needs it, my current shell command is the following:

CC=/Users/tanis/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc CXX=/Users/tanis/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++ AR=/Users/tanis/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ar CFLAGS=--sysroot=/Users/tanis/android-ndk/platforms/android-24/arch-arm/ cargo build --no-default-features --target armv7-linux-androideabi --lib