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

Enforce static link by setting env OPENSSL_STATIC failed #1792

Closed
sammyne opened this issue Jan 14, 2023 · 2 comments
Closed

Enforce static link by setting env OPENSSL_STATIC failed #1792

sammyne opened this issue Jan 14, 2023 · 2 comments

Comments

@sammyne
Copy link
Contributor

sammyne commented Jan 14, 2023

Problem

It seems that rust-openssl cannot be statically linked with env OPENSSL_STATIC set in .cargo/config.toml under project root.

Prerequisite

  • openssl: 0.10.42

For reproduction, a github repo has been made as https://github.com/sammyne/rust-openssl-cannot-link-statically, and steps for reproductions go as follow.

Reproduction

1. Start the container as building env

docker run -it --rm     \
  -v $PWD:/workspace    \
  -w /workspace         \
  rust:1.65.0-bullseye  \
  bash

2. Build the project within the started container

cargo build

3. Check linkage with ldd

ldd target/debug/rust-openssl-cannot-link-statically

Got output log as

        linux-vdso.so.1 (0x00007ffc00d2c000)
        libssl.so.1.1 => /usr/lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007ff37e652000)
        libcrypto.so.1.1 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007ff37e35e000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff37e358000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ff37e33e000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff37e31c000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff37e147000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ff37e745000)

where libssl.a and libcrypto.a should be used instead of libssl.so.1.1 and libcrypto.so.1.1.

Really appreciate if someone could help me out~

@sfackler
Copy link
Owner

It looks like you are running into rust-lang/pkg-config-rs#102.

@juliusl
Copy link

juliusl commented Feb 10, 2023

For anyone else that might've arrived here,

When you specify OPENSSL_STATIC, you need to include OPENSSL_LIB_DIR and OPENSSL_INCLUDE_DIR if you want to avoid the pkg-config behavior. When you specify OPENSSL_LIB_DIR you need to give it the directory with the *.a files. Other search results may say to use /usr/lib or /usr/lib64 but for example on ubuntu 22.04 it should be /usr/lib/x86_64-linux-gnu.

For example,

OPENSSL_STATIC=1 OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu OPENSSL_INCLUDE_DIR=/usr/include/openssl cargo build

Note that this will likely be different if you're cross-compiling from the same image.

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

3 participants