Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build script error while cross-compiling for Android #54

Closed
astonbitecode opened this issue Jun 10, 2019 · 13 comments
Closed

Build script error while cross-compiling for Android #54

astonbitecode opened this issue Jun 10, 2019 · 13 comments

Comments

@astonbitecode
Copy link

Hi,

my crate has a dependency on rust_libloading 0.5.1 and when cross-compiling for Android, I get the following error:

error: failed to run custom build command for `libloading v0.5.1`
process didn't exit successfully: `/home/aston/rust-keylock-android/rust/target/release/build/libloading-c12fda81b5e744cc/build-script-build` (exit code: 1)

--- stdout
...
...
...
--- stderr
error occurred: Command "/home/aston/rust-keylock-android/android-toolchain/bin/arm-linux-androideabi-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-Wall" "-Wextra" "-o" "/home/aston/rust-keylock-android/rust/target/release/build/libloading-7b0f9f5769dc954d/out/src/os/unix/global_static.o" "-c" "src/os/unix/global_static.c" with args "arm-linux-androideabi-gcc" did not execute successfully (status code exit code: 1).

Using the 0.4.3 release there is not an issue, since only after 0.50 there is building of global_static.

Do I need to do something special to build global_static for Android? Can I do something to correct/avoid this error?

@nagisa
Copy link
Owner

nagisa commented Jun 10, 2019

Please do not omit the actual error messages from the compiler.

@astonbitecode
Copy link
Author

Sorry for that.

Here is the full output

Entered Base directory /home/aston/rust-keylock-android
   Compiling libloading v0.5.1
   Compiling hyper-tls v0.3.2
error: failed to run custom build command for `libloading v0.5.1`
process didn't exit successfully: `/home/aston/rust-keylock-android/rust/target/release/build/libloading-c12fda81b5e744cc/build-script-build` (exit code: 1)
--- stdout
cargo:rustc-link-lib=dl
TARGET = Some("x86_64-unknown-linux-gnu")
OPT_LEVEL = Some("3")
HOST = Some("x86_64-unknown-linux-gnu")
CC_x86_64-unknown-linux-gnu = None
CC_x86_64_unknown_linux_gnu = None
HOST_CC = None
CC = Some("/home/aston/rust-keylock-android/android-toolchain/bin/arm-linux-androideabi-gcc")
CFLAGS_x86_64-unknown-linux-gnu = None
CFLAGS_x86_64_unknown_linux_gnu = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
running: "/home/aston/rust-keylock-android/android-toolchain/bin/arm-linux-androideabi-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-Wall" "-Wextra" "-o" "/home/aston/rust-keylock-android/rust/target/release/build/libloading-7b0f9f5769dc954d/out/src/os/unix/global_static.o" "-c" "src/os/unix/global_static.c"
cargo:warning=In file included from src/os/unix/global_static.c:1:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/pthread.h:37:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/time.h:33:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/sys/time.h:37:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/sys/select.h:36:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/signal.h:37:
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:79:20: error: expected ';' at end of declaration list
cargo:warning=struct sigaction { __SIGACTION_BODY };
cargo:warning=                   ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:73:18: note: expanded from macro '__SIGACTION_BODY'
cargo:warning=    sighandler_t sa_handler; \
cargo:warning=                 ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/asm/signal.h:85:22: note: expanded from macro 'sa_handler'
cargo:warning=#define sa_handler _u._sa_handler
cargo:warning=                     ^
cargo:warning=In file included from src/os/unix/global_static.c:1:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/pthread.h:37:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/time.h:33:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/sys/time.h:37:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/sys/select.h:36:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/signal.h:37:
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:79:20: error: expected ')'
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:74:12: note: expanded from macro '__SIGACTION_BODY'
cargo:warning=    void (*sa_sigaction)(int, struct siginfo*, void*); \
cargo:warning=           ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/asm/signal.h:86:24: note: expanded from macro 'sa_sigaction'
cargo:warning=#define sa_sigaction _u._sa_sigaction
cargo:warning=                       ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:79:20: note: to match this '('
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:74:10: note: expanded from macro '__SIGACTION_BODY'
cargo:warning=    void (*sa_sigaction)(int, struct siginfo*, void*); \
cargo:warning=         ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:79:20: error: duplicate member '_u'
cargo:warning=struct sigaction { __SIGACTION_BODY };
cargo:warning=                   ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:74:12: note: expanded from macro '__SIGACTION_BODY'
cargo:warning=    void (*sa_sigaction)(int, struct siginfo*, void*); \
cargo:warning=           ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/asm/signal.h:86:22: note: expanded from macro 'sa_sigaction'
cargo:warning=#define sa_sigaction _u._sa_sigaction
cargo:warning=                     ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:79:20: note: previous declaration is here
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:73:18: note: expanded from macro '__SIGACTION_BODY'
cargo:warning=    sighandler_t sa_handler; \
cargo:warning=                 ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/asm/signal.h:85:20: note: expanded from macro 'sa_handler'
cargo:warning=#define sa_handler _u._sa_handler
cargo:warning=                   ^
cargo:warning=In file included from src/os/unix/global_static.c:1:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/pthread.h:37:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/time.h:33:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/sys/time.h:37:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/sys/select.h:36:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/signal.h:37:
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:80:22: error: expected ';' at end of declaration list
cargo:warning=struct sigaction64 { __SIGACTION_BODY };
cargo:warning=                     ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:73:18: note: expanded from macro '__SIGACTION_BODY'
cargo:warning=    sighandler_t sa_handler; \
cargo:warning=                 ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/asm/signal.h:85:22: note: expanded from macro 'sa_handler'
cargo:warning=#define sa_handler _u._sa_handler
cargo:warning=                     ^
cargo:warning=In file included from src/os/unix/global_static.c:1:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/pthread.h:37:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/time.h:33:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/sys/time.h:37:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/sys/select.h:36:
cargo:warning=In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/signal.h:37:
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:80:22: error: expected ')'
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:74:12: note: expanded from macro '__SIGACTION_BODY'
cargo:warning=    void (*sa_sigaction)(int, struct siginfo*, void*); \
cargo:warning=           ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/asm/signal.h:86:24: note: expanded from macro 'sa_sigaction'
cargo:warning=#define sa_sigaction _u._sa_sigaction
cargo:warning=                       ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:80:22: note: to match this '('
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:74:10: note: expanded from macro '__SIGACTION_BODY'
cargo:warning=    void (*sa_sigaction)(int, struct siginfo*, void*); \
cargo:warning=         ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:80:22: error: duplicate member '_u'
cargo:warning=struct sigaction64 { __SIGACTION_BODY };
cargo:warning=                     ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:74:12: note: expanded from macro '__SIGACTION_BODY'
cargo:warning=    void (*sa_sigaction)(int, struct siginfo*, void*); \
cargo:warning=           ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/asm/signal.h:86:22: note: expanded from macro 'sa_sigaction'
cargo:warning=#define sa_sigaction _u._sa_sigaction
cargo:warning=                     ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:80:22: note: previous declaration is here
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:73:18: note: expanded from macro '__SIGACTION_BODY'
cargo:warning=    sighandler_t sa_handler; \
cargo:warning=                 ^
cargo:warning=/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/asm/signal.h:85:20: note: expanded from macro 'sa_handler'
cargo:warning=#define sa_handler _u._sa_handler
cargo:warning=                   ^
cargo:warning=6 errors generated.
exit code: 1

--- stderr


error occurred: Command "/home/aston/rust-keylock-android/android-toolchain/bin/arm-linux-androideabi-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-Wall" "-Wextra" "-o" "/home/aston/rust-keylock-android/rust/target/release/build/libloading-7b0f9f5769dc954d/out/src/os/unix/global_static.o" "-c" "src/os/unix/global_static.c" with args "arm-linux-androideabi-gcc" did not execute successfully (status code exit code: 1).



warning: build failed, waiting for other jobs to finish...
error: build failed

@nagisa
Copy link
Owner

nagisa commented Jun 10, 2019

It seems entirely like an issue with your toolchain. Does running something like this:

echo -e '#include<pthread.h>\nint main(void) { return 0; }' | /home/aston/rust-keylock-android/android-toolchain/bin/arm-linux-androideabi-gcc -xc -

work for you? This tests compilation of a trivially correct program and should definitely work on any POSIX system with gcc toolchain.

@astonbitecode
Copy link
Author

The command is executed with no errors and a.out is created.

file a.out gives:
a.out: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /system/, not stripped

@nagisa
Copy link
Owner

nagisa commented Jun 10, 2019

Just for reference, does building this file manually (outside of cargo, without any additional flags other than just the file specified) also work fine? What if you also copy all the flags?

/home/aston/rust-keylock-android/android-toolchain/bin/arm-linux-androideabi-gcc "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-Wall" "-Wextra" "-c" "src/os/unix/global_static.c"

@astonbitecode
Copy link
Author

Thanks for the help and fast responses!

The command

/home/aston/rust-keylock-android/android-toolchain/bin/arm-linux-androideabi-gcc "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-Wall" "-Wextra" "-c" "./global_static.c"

produces the same errors with cargo I guess:

In file included from ./global_static.c:1:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/pthread.h:37:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/time.h:33:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/sys/time.h:37:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/sys/select.h:36:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/signal.h:37:
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:79:20: error: 
      expected ';' at end of declaration list
struct sigaction { __SIGACTION_BODY };
                   ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:73:18: note: 
      expanded from macro '__SIGACTION_BODY'
    sighandler_t sa_handler; \
                 ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/asm/signal.h:85:22: note: 
      expanded from macro 'sa_handler'
#define sa_handler _u._sa_handler
                     ^
In file included from ./global_static.c:1:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/pthread.h:37:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/time.h:33:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/sys/time.h:37:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/sys/select.h:36:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/signal.h:37:
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:79:20: error: 
      expected ')'
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:74:12: note: 
      expanded from macro '__SIGACTION_BODY'
    void (*sa_sigaction)(int, struct siginfo*, void*); \
           ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/asm/signal.h:86:24: note: 
      expanded from macro 'sa_sigaction'
#define sa_sigaction _u._sa_sigaction
                       ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:79:20: note: 
      to match this '('
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:74:10: note: 
      expanded from macro '__SIGACTION_BODY'
    void (*sa_sigaction)(int, struct siginfo*, void*); \
         ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:79:20: error: 
      duplicate member '_u'
struct sigaction { __SIGACTION_BODY };
                   ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:74:12: note: 
      expanded from macro '__SIGACTION_BODY'
    void (*sa_sigaction)(int, struct siginfo*, void*); \
           ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/asm/signal.h:86:22: note: 
      expanded from macro 'sa_sigaction'
#define sa_sigaction _u._sa_sigaction
                     ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:79:20: note: 
      previous declaration is here
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:73:18: note: 
      expanded from macro '__SIGACTION_BODY'
    sighandler_t sa_handler; \
                 ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/asm/signal.h:85:20: note: 
      expanded from macro 'sa_handler'
#define sa_handler _u._sa_handler
                   ^
In file included from ./global_static.c:1:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/pthread.h:37:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/time.h:33:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/sys/time.h:37:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/sys/select.h:36:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/signal.h:37:
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:80:22: error: 
      expected ';' at end of declaration list
struct sigaction64 { __SIGACTION_BODY };
                     ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:73:18: note: 
      expanded from macro '__SIGACTION_BODY'
    sighandler_t sa_handler; \
                 ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/asm/signal.h:85:22: note: 
      expanded from macro 'sa_handler'
#define sa_handler _u._sa_handler
                     ^
In file included from ./global_static.c:1:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/pthread.h:37:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/time.h:33:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/sys/time.h:37:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/sys/select.h:36:
In file included from /home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/signal.h:37:
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:80:22: error: 
      expected ')'
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:74:12: note: 
      expanded from macro '__SIGACTION_BODY'
    void (*sa_sigaction)(int, struct siginfo*, void*); \
           ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/asm/signal.h:86:24: note: 
      expanded from macro 'sa_sigaction'
#define sa_sigaction _u._sa_sigaction
                       ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:80:22: note: 
      to match this '('
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:74:10: note: 
      expanded from macro '__SIGACTION_BODY'
    void (*sa_sigaction)(int, struct siginfo*, void*); \
         ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:80:22: error: 
      duplicate member '_u'
struct sigaction64 { __SIGACTION_BODY };
                     ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:74:12: note: 
      expanded from macro '__SIGACTION_BODY'
    void (*sa_sigaction)(int, struct siginfo*, void*); \
           ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/asm/signal.h:86:22: note: 
      expanded from macro 'sa_sigaction'
#define sa_sigaction _u._sa_sigaction
                     ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:80:22: note: 
      previous declaration is here
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/bits/signal_types.h:73:18: note: 
      expanded from macro '__SIGACTION_BODY'
    sighandler_t sa_handler; \
                 ^
/home/aston/rust-keylock-android/android-toolchain/bin/../sysroot/usr/include/asm/signal.h:85:20: note: 
      expanded from macro 'sa_handler'
#define sa_handler _u._sa_handler
                   ^
6 errors generated.

In the case it helps, I use ndk-r10e and I build the toolchain to support platform-16 as a minimum:

$ANDROID_NDK/build/tools/make-standalone-toolchain.sh --platform=android-16 --arch=arm --install-dir=android-toolchain

@astonbitecode
Copy link
Author

Hey, without any flags:

/home/aston/rust-keylock-android/android-toolchain/bin/arm-linux-androideabi-gcc "-c" "./global_static.c"

It succeeds.

global_static.o is created and no errors...

@nagisa
Copy link
Owner

nagisa commented Jun 10, 2019

I think the reason why this might be happening is because you invoke rustc/cargo like this (assuming bash shell):

CC=arm-linux-androideabi-gcc cargo build

and cargo is really building for your host target (x86_64-unknown-linux-gnu), rather than for android (arm-linux-androideabi) but with a wrong C compiler. TARGET = Some("x86_64-unknown-linux-gnu") in one of the outputs above is the giveaway here. Your cargo invocation should look something like this instead:

cargo build --target=arm-linux-androideabl

or perhaps

CC=arm-linux-androideabi-gcc cargo build --target=arm-linux-androideabl

@astonbitecode
Copy link
Author

TARGET = Some("x86_64-unknown-linux-gnu") in one of the outputs above is the giveaway here

You are right, but this is weird I guess, because I specify already the compiler in the cargo build. This is the command that I use:

CC="${ANDROID_TOOLCHAIN_DIR}/bin/arm-linux-androideabi-gcc" AR="${ANDROID_TOOLCHAIN_DIR}/bin/arm-linux-androideabi-ar" OPENSSL_DIR=${OPENSSL_BUILD_DIR} OPENSSL_LIB_DIR=${OPENSSL_BUILD_DIR}/lib OPENSSL_INCLUDE_DIR=${OPENSSL_BUILD_DIR}/include OPENSSL_STATIC=true $CARGO_HOME/bin/cargo build --target=arm-linux-androideabi --release

Generally, my concern is that before libloading 0.5.x I didn't have issues for building android. If I use 0.4.3, there are no errors and the created library is correct format:

ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, with debug_info, not stripped

Maybe it is needed something more to configure correctly the cc crate that you use in the build script.

@astonbitecode
Copy link
Author

Ok, so here is the thing:

libloading is used both from my actual code and from the build script. The build script compiles global_static.c with CARGO_CFG_TARGET_OS linux and then, the actual build of my crate compiles it with target android.

I am not sure if when global_static.c is compiled for the second time, the output objects are generated again... Maybe you should clean the output before each build script invocation?

@astonbitecode
Copy link
Author

Is this maybe related?

Please have a look at this comment specifically.

astonbitecode added a commit to astonbitecode/j4rs that referenced this issue Jun 14, 2019
astonbitecode added a commit to astonbitecode/j4rs that referenced this issue Jun 14, 2019
@nagisa
Copy link
Owner

nagisa commented Jun 14, 2019

libloading is used both from my actual code and from the build script.

Yeah specifying CC will force build.rs script to use your android CC for all targets including the one built for your host (which is how libloading will be built when used for build scripts). You would have a similar problem for any crate which has native dependencies and is built for your host.

Try perhaps CC_arm-linux-androideabi=... instead of plain CC (and similarly for AR). You can also configure these tools in your cargo config. Alternatively, export CC_x86_64-unknown-linux-gnu=your_host_cc in addition to CC=your_android_cc.

Generally, my concern is that before libloading 0.5.x I didn't have issues for building android. If I use 0.4.3, there are no errors and the created library is correct format:

0.4.3 did not depend on the C file that 0.5 series depend on and therefore CC was not consequential for that version.

@astonbitecode
Copy link
Author

Using CC_arm_linux_androideabi="${ANDROID_TOOLCHAIN_DIR}/bin/arm-linux-androideabi-gcc" AR_arm_linux_androideabi="${ANDROID_TOOLCHAIN_DIR}/bin/arm-linux-androideabi-ar" for building did the trick, thank you very much.

If you believe there is nothing to further do or improve for your project regarding this, feel free to close the issue.

Thanks for the help and for the libloading crate, of course.

@nagisa nagisa closed this as completed Jun 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants