jni-rs icon indicating copy to clipboard operation
jni-rs copied to clipboard

Error when cross compiling

Open davidhoyt opened this issue 3 years ago • 1 comments

I am looking to cross-compile logic which launches a VM. The build is to be done in a Linux VM and produce artifacts that can be used from a mac.

Host: Linux (Rocky 8, x86_64-unknown-linux-gnu) Target: OS X (x86_64-apple-darwin)

This was failing with:

          Undefined symbols for architecture x86_64:
            "_JNI_CreateJavaVM", referenced from:
                jni::wrapper::java_vm::vm::JavaVM::new::h9c107e1f2b8d2a3b in libjni-81a21f72b51a82be.rlib(jni-81a21f72b51a82be.jni.14b22281-cgu.3.rcgu.o)
          ld: symbol(s) not found for architecture x86_64

In reference to https://github.com/jni-rs/jni-rs/blob/master/build.rs#L60-L64 it was asserted in discussion with other Rust devs that:

build scripts should not use cfg! to express conditional compilation, but the equivalent environment variables because cfg! in a build script receives information about the host computer, not the target computer, because it is being used to conditionally compile the build script and the build script is being compiled on the host computer. ... instead check that env::var("CARGO_CFG_TARGET_OS") (not env!) is equal to "macos".

davidhoyt avatar Jul 13 '22 07:07 davidhoyt

I could also avoid this if PR #293 were merged.

davidhoyt avatar Jul 13 '22 07:07 davidhoyt