openssl dependency
I need a few more steps to build a program depending on openssl-sys (via hyper). These are tested on archlinux:
- Fixing
openssl/hmac.hnot found: copying the target's /usr/include/openssl to /arm-gcc-prefix/include - Fixing linking:
- Copy the target's libssl.so, libcrypto.so, libz.so to /arm-gcc-prefix/lib
- Explicitly link to libz, used by libcrypto:
cargo rustc --target=arm-unknown-linux-gnueabihf --release -- -lz -Clinker=arm-linux-gnueabihf-gcc
Thanks for your report!
copying the target's /usr/include/openssl to /arm-gcc-prefix/include Copy the target's libssl.so, libcrypto.so, libz.so to /arm-gcc-prefix/lib
I have done this before, it ensures you use a library that's ABI compatible with the target libraries. Did you modify your system installation, i.e. /usr, when you say "copy (..) to /arm-gcc-prefix/include"?
I would prefer to suggest the readers installing the libraries in a user owned directory and then passing --sysroot to gcc instead of modifying the system directories but I'm not sure how feasible the former approach is (setting CFLAGS might work?).
Explicitly link to libz, used by libcrypto:
This sounds like a bug, it should never be necessary to pass a -l flag to rustc using cargo rustc. Cargo's build.rs should take care of these linker flags.
Yes, I dropped them in its installation in /usr/arm-linux-gnueabihf.
Your suggestion works. I copy them to $PWD/arm/include and $PWD/arm/lib, then build with:
TARGET_CFLAGS="-I $PWD/arm/include" cargo rustc --target arm-unknown-linux-gnueabihf -- -C linker=arm-linux-gnueabihf-gcc -L $PWD/arm/lib -lz
Leaving out -lz fails to resolve deflate symbols, even if libz.so.1 exists in $PWD/arm/lib:
Compiling luser v0.1.0 (file:///home/hdhoang/luser)
error: linking with `arm-linux-gnueabihf-gcc` failed: exit code: 1
note: "arm-linux-gnueabihf-gcc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-L" "/home/hdhoang/.multirust/toolchains/nightly/lib/rustlib/arm-unknown-linux-gnueabihf/lib" "/home/hdhoang/luser/target/arm-unknown-linux-gnueabihf/debug/luser.0.o" "-o" "/home/hdhoang/luser/target/arm-unknown-linux-gnueabihf/debug/luser" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/home/hdhoang/luser/arm/lib" "-L"
[........]
/toolchains/nightly/lib/rustlib/arm-unknown-linux-gnueabihf/lib/liblibc-fd663c41.rlib" "/home/hdhoang/.multirust/toolchains/nightly/lib/rustlib/arm-unknown-linux-gnueabihf/lib/libcore-fd663c41.rlib" "-l" "ssl" "-l" "crypto" "-l" "dl" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-Wl,-rpath,$ORIGIN/../../../../.multirust/toolchains/nightly/lib/rustlib/arm-unknown-linux-gnueabihf/lib" "-Wl,-rpath,/usr/local/lib/rustlib/arm-unknown-linux-gnueabihf/lib" "-Wl,--enable-new-dtags" "-l" "compiler-rt"
note: /usr/bin/arm-linux-gnueabihf-ld: warning: libz.so.1, needed by /home/hdhoang/luser/arm/lib/libcrypto.so, not found (try using -rpath or -rpath-link)
/home/hdhoang/luser/arm/lib/libcrypto.so: undefined reference to `deflateInit_'
guys, I'm new to rust and i keep having this error when i try to cross compile my code. i really need help. I'm still a student and i want to learn.
Build failed, waiting for other jobs to finish... error: failed to run custom build command for
openssl v0.7.13Process didn't exit successfully:/home/kenichi/Documents/Projects/Rust/rustpi_app/target/debug/build/openssl-8f82a1ac7a7f09d7/build-script-build(exit code: 101)

what can i do to get around this problem? i also tried compiling other code without dependency with openssl and it doesn't give me any error. thanks in advance
@KennyClark7 It appears the Open SSL headers in Debian recently moved to a multi-arch directory structure.
Symlinking the current architecture’s config header into the directory where the compiler is told to find the OpenSSL headers seems to work for me:
# ln -s /usr/include/x86_64-linux-gnu/openssl/opensslconf.h /usr/include/openssl/opensslconf.h
Or if you’re cross-compiling, doing the same for /usr/x86_64-w64-mingw32, or whatever.
@andreastt i already solved this one, i downloaded the dependencies required by the openssl for raspberry pi. anyway, thankyou for your reply..
I know this is an old issue, but I came across it while Googling for cross-compiling a Rust project that depends on OpenSSL. An alternative (that perhaps didn't exist back in 2016) is to enable the vendored feature when depending on openssl. This will compile OpenSSL from source as part of the build, rather than expecting it to already be available (for the target architecture) on your system.