Whenever I try to compile I get
= note: /usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libnative_tls-e4af7be01e0cc1c7.rlib(native_tls-e4af7be01e0cc1c7.native_tls.c3tq55qu-cgu.0.rcgu.o): in function `<openssl::stack::StackRef<T>>::len':
/home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/src/stack.rs:171: undefined reference to `sk_num'
/usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libnative_tls-e4af7be01e0cc1c7.rlib(native_tls-e4af7be01e0cc1c7.native_tls.c3tq55qu-cgu.0.rcgu.o): in function `<openssl::stack::StackRef<T>>::_get':
/home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/src/stack.rs:242: undefined reference to `sk_value'
/usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libopenssl-a51d9ef9dbb88c83.rlib(openssl-a51d9ef9dbb88c83.openssl.27r2wowg-cgu.11.rcgu.o): in function `openssl::ssl::compat::tls_method':
/home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/src/ssl/mod.rs:2546: undefined reference to `SSLv23_method'
/usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libopenssl-a51d9ef9dbb88c83.rlib(openssl-a51d9ef9dbb88c83.openssl.27r2wowg-cgu.15.rcgu.o): in function `<openssl::stack::Stack<T>>::new':
/home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/src/stack.rs:40: undefined reference to `sk_new_null'
/usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libopenssl-a51d9ef9dbb88c83.rlib(openssl-a51d9ef9dbb88c83.openssl.27r2wowg-cgu.15.rcgu.o): in function `<openssl::stack::Stack<T> as core::ops::drop::Drop>::drop':
/home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/src/stack.rs:50: undefined reference to `sk_free'
/usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libopenssl-a51d9ef9dbb88c83.rlib(openssl-a51d9ef9dbb88c83.openssl.27r2wowg-cgu.15.rcgu.o): in function `<openssl::stack::StackRef<T>>::pop':
/home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/src/stack.rs:232: undefined reference to `sk_pop'
/usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libopenssl-a51d9ef9dbb88c83.rlib(openssl-a51d9ef9dbb88c83.openssl.27r2wowg-cgu.4.rcgu.o): in function `openssl::version::number':
/home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/src/version.rs:51: undefined reference to `SSLeay'
/usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libopenssl-a51d9ef9dbb88c83.rlib(openssl-a51d9ef9dbb88c83.openssl.27r2wowg-cgu.6.rcgu.o): in function `openssl::x509::compat::X509_up_ref':
/home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-0.9.24/src/x509/mod.rs:1172: undefined reference to `CRYPTO_add_lock'
/usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libopenssl_sys-51d0c50f2e67767f.rlib(openssl_sys-51d0c50f2e67767f.openssl_sys.afwyjyem-cgu.9.rcgu.o): in function `openssl_sys::init::{{closure}}':
/home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.40/src/lib.rs:150: undefined reference to `SSL_library_init'
/usr/bin/ld: /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.40/src/lib.rs:151: undefined reference to `SSL_load_error_strings'
/usr/bin/ld: /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.40/src/lib.rs:152: undefined reference to `OPENSSL_add_all_algorithms_noconf'
/usr/bin/ld: /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.40/src/lib.rs:154: undefined reference to `CRYPTO_num_locks'
/usr/bin/ld: /home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.40/src/lib.rs:164: undefined reference to `CRYPTO_set_locking_callback'
/usr/bin/ld: /home/trent/Documents/projects/coding/rust/website/auth/target/debug/deps/libopenssl_sys-51d0c50f2e67767f.rlib(openssl_sys-51d0c50f2e67767f.openssl_sys.afwyjyem-cgu.9.rcgu.o): in function `openssl_sys::init::set_id_callback':
/home/trent/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.40/src/lib.rs:139: undefined reference to `CRYPTO_set_id_callback'
collect2: error: ld returned 1 exit status
Complete log
I have both OpenSSL and OpenSSL-1.0 installed. I have tried using both Rust stable and nightly. I've also tried to include different versions of the openssl crate, but I think Cargo is just building the version of the crate that I think grpc is using. I'm on Arch Linux.
Your project is using openssl 0.9.x (probably via tls-api-native-tls 0.1.x -> native-tls 0.1.x -> openssl 0.9.x), which doesn't support OpenSSL 1.1.1. I'm also on Arch Linux and I've had to update my programs to openssl 0.10 in order to use OpenSSL 1.1.1.
In your case, tls-api-native-tls needs to be updated to depend on native-tls 0.2.x, which uses openssl 0.10.x (which does support OpenSSL 1.1.1). There is an open issue about this.
If that's too complicated, you can also use various environment variables to tell openssl-sys's build script which installation of OpenSSL you'd like to use. If you'd prefer using OpenSSL 1.0.x, enter the following commands in your shell:
$ cargo clean
$ OPENSSL_INCLUDE_DIR=/usr/include/openssl-1.0 OPENSSL_LIB_DIR=/usr/lib/openssl-1.0 cargo build
(Note: the paths above may be specific to Arch Linux.)
For more information on the environment variables you can use to configure openssl-sys, see Manual configuration.
Related
I'm trying to develop a small utility using the dialog library in C (the dialog command in linux).
On fedora linux works fine, but if i try to compile it on debian with the command:
gcc -ldialog -lncurses -I/usr/include dialog_test.c
I get the following error:
vetinari#ankhmorpork:~/Projects/Other/test$ gcc -ldialog -I/usr/include dialog_test.c
/usr/bin/ld: /tmp/ccX6fPYB.o: warning: relocation against `dialog_vars' in read-only section `.text'
/usr/bin/ld: /tmp/ccX6fPYB.o: in function `main':
dialog_test.c:(.text+0x5c): undefined reference to `init_dialog'
/usr/bin/ld: dialog_test.c:(.text+0x79): undefined reference to `dialog_yesno'
/usr/bin/ld: dialog_test.c:(.text+0xae): undefined reference to `dialog_menu'
/usr/bin/ld: dialog_test.c:(.text+0xbc): undefined reference to `dialog_vars'
/usr/bin/ld: dialog_test.c:(.text+0xc5): undefined reference to `end_dialog'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
The dialog command works fine.
Anyone has any idea why it isn't working on debian?
(Answer for the wiki sake, in case someone comes by here later)
You have to put the libraries you want to link at the end of the gcc command, like this:
gcc dialog_test.c -ldialog -lncurses
The reason is explained here: The way the linker looks up symbols it has to first see the reference, and then the library prodiving the symbol
Additionally, the dialog library might have other dependencies than ncurses. There is explanation how to find out what to include and what to link here, in short: dialog-config should tell you about it.
In this specific case, what worked for me (ubuntu 20.04) was linking ncursesw instead of ncurses.
After that, I was left with an
undefined reference to `sqrt'
linker error, which can be solved by linking the match library using -lm.
So, in total, this command works:
gcc dialog_test.c -ldialog -lncursesw -lm
Environment
Linux (Pop!_OS if that matters, which means it's almost Ubuntu).
$ cargo --version
cargo 1.41.0 (626f0f40e 2019-12-03)
$ rustc --version
rustc 1.41.0 (5e1a79984 2020-01-27)
What I did
$ cargo new xxx
Created binary (application) `xxx` package
I edited Cargo.toml to look like this:
[package]
name = "xxx"
version = "0.1.0"
authors = ["Martin Marconcini <xxx#xxx.com>"]
edition = "2018"
[dependencies]
git2 = "0.12.0"
And main.rs:
use git2::Repository;
fn main() {
println!("Hello, world!");
let repo = match Repository::open("fake/path") {
Ok(repo) => repo,
Err(e) => panic!("Failed to init {}", e),
};
}
Issue
I know fake/path won't work but I expect the program to build, link, and panic when run. Instead, when I do cargo run, here is what I get:
$ cargo run
Updating crates.io index
Compiling libc v0.2.67
Compiling pkg-config v0.3.17
Compiling autocfg v1.0.0
Compiling smallvec v1.2.0
Compiling matches v0.1.8
Compiling bitflags v1.2.1
Compiling log v0.4.8
Compiling cfg-if v0.1.10
Compiling percent-encoding v2.1.0
Compiling openssl-probe v0.1.2
Compiling unicode-bidi v0.3.4
Compiling unicode-normalization v0.1.12
Compiling jobserver v0.1.21
Compiling idna v0.2.0
Compiling cc v1.0.50
Compiling url v2.1.1
Compiling libz-sys v1.0.25
Compiling openssl-sys v0.9.54
Compiling libssh2-sys v0.2.16
Compiling libgit2-sys v0.11.0+0.99.0
Compiling git2 v0.12.0
Compiling xxx v0.1.0 (/home/martin/dev/rust/xxx)
warning: unused variable: `repo`
--> src/main.rs:6:9
|
6 | let repo = match Repository::open("/fake/path") {
| ^^^^ help: consider prefixing with an underscore: `_repo`
|
= note: `#[warn(unused_variables)]` on by default
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/martin/dev/rust/xxx/target/debug/deps/xxx-fe6ac189d82a9620.1g3apxivazecmby1.rcgu.o" "/home/martin/dev/rust/xxx/target/debug/deps/xxx-fe6ac189d82a9620.1ktaa7mhzl12qb8s.rcgu.o" "/home/martin/dev/rust/xxx/target/debug/deps/xxx-fe6ac189d82a9620.1of15nz9rghhwcp.rcgu.o" "/home/martin/dev/rust/xxx/target/debug/deps/xxx-fe6ac189d82a9620.1pzhxyvu6x3rpyd4.rcgu.o" "/home/martin/dev/rust/xxx/target/debug/deps/xxx-fe6ac189d82a9620.1xjrgwir8ul0gxyn.rcgu.o" "/home/martin/dev/rust/xxx/target/debug/deps/xxx-fe6ac189d82a9620.236nnnkop2p1q7o.rcgu.o" "/home/martin/dev/rust/xxx/target/debug/deps/xxx-fe6ac189d82a9620.346upd227a1u5o1x.rcgu.o" "/home/martin/dev/rust/xxx/target/debug/deps/xxx-fe6ac189d82a9620.4vpli3o8gp9bo7bb.rcgu.o" "/home/martin/dev/rust/xxx/target/debug/deps/xxx-fe6ac189d82a9620.fjvxd6ccfznqzmo.rcgu.o" "-o" "/home/martin/dev/rust/xxx/target/debug/deps/xxx-fe6ac189d82a9620" "/home/martin/dev/rust/xxx/target/debug/deps/xxx-fe6ac189d82a9620.2bpv5j881nolkdhg.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/home/martin/dev/rust/xxx/target/debug/deps" "-L" "/home/martin/dev/rust/xxx/target/debug/build/libgit2-sys-9a380c1f1af1ff52/out/build" "-L" "/usr/lib/x86_64-linux-gnu" "-L" "/home/martin/dev/rust/xxx/target/debug/build/libssh2-sys-76c9f6db4b487643/out/build" "-L" "/usr/lib/x86_64-linux-gnu" "-L" "/home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/martin/dev/rust/xxx/target/debug/deps/libgit2-e4070b896a12b23e.rlib" "/home/martin/dev/rust/xxx/target/debug/deps/libopenssl_probe-02ad0051245c142f.rlib" "/home/martin/dev/rust/xxx/target/debug/deps/liburl-752d8a16592303c8.rlib" "/home/martin/dev/rust/xxx/target/debug/deps/libpercent_encoding-3f375297ed36a953.rlib" "/home/martin/dev/rust/xxx/target/debug/deps/libidna-a849b89d54cc2589.rlib" "/home/martin/dev/rust/xxx/target/debug/deps/libunicode_normalization-81788f9135a21d94.rlib" "/home/martin/dev/rust/xxx/target/debug/deps/libsmallvec-e36b82e338fe18d3.rlib" "/home/martin/dev/rust/xxx/target/debug/deps/libunicode_bidi-901a064d2af6777d.rlib" "/home/martin/dev/rust/xxx/target/debug/deps/libmatches-ccee7833d11c4363.rlib" "/home/martin/dev/rust/xxx/target/debug/deps/liblog-aba47d2dbe489265.rlib" "/home/martin/dev/rust/xxx/target/debug/deps/libcfg_if-fd0f59c38961bb3a.rlib" "/home/martin/dev/rust/xxx/target/debug/deps/liblibgit2_sys-b077f325e2a7224c.rlib" "/home/martin/dev/rust/xxx/target/debug/deps/liblibssh2_sys-187467b0efb35c13.rlib" "/home/martin/dev/rust/xxx/target/debug/deps/libopenssl_sys-b21cd1cefc781387.rlib" "/home/martin/dev/rust/xxx/target/debug/deps/liblibz_sys-c72b1cae7b178c73.rlib" "/home/martin/dev/rust/xxx/target/debug/deps/liblibc-a68ece9bb60c0ea2.rlib" "/home/martin/dev/rust/xxx/target/debug/deps/libbitflags-468acf5fe2f3e68a.rlib" "-Wl,--start-group" "/home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-9d59e25e2eb2384d.rlib" "/home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-4affccee0db9d60e.rlib" "/home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-cd6b495608e342d1.rlib" "/home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-347d88a586b28b4c.rlib" "/home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace-46f3dc0b263b900a.rlib" "/home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libbacktrace_sys-6789aa6fbcfdf14c.rlib" "/home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-9f9436f1ab051941.rlib" "/home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-ad8ec269e6d86d01.rlib" "/home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-3699f95d33475c27.rlib" "/home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-fe798441633702e1.rlib" "/home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-979288990efe6065.rlib" "/home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-2181f1e1dd7399d7.rlib" "/home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-b8952fd765001238.rlib" "-Wl,--end-group" "/home/martin/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-e99fedbd2b621435.rlib" "-Wl,-Bdynamic" "-lz" "-lssl" "-lcrypto" "-lz" "-lutil" "-ldl" "-lutil" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil"
= note: /usr/bin/ld: /home/martin/dev/rust/xxx/target/debug/deps/liblibssh2_sys-187467b0efb35c13.rlib(libgcrypt.o): in function `_libssh2_rsa_new':
(.text+0x48): undefined reference to `gcry_sexp_build'
/usr/bin/ld: (.text+0x77): undefined reference to `gcry_sexp_build'
/usr/bin/ld: /home/martin/dev/rust/xxx/target/debug/deps/liblibssh2_sys-187467b0efb35c13.rlib(libgcrypt.o): in function `_libssh2_rsa_sha1_verify':
(.text+0xcb): undefined reference to `gcry_md_hash_buffer'
/usr/bin/ld: (.text+0xe8): undefined reference to `gcry_sexp_build'
/usr/bin/ld: (.text+0x103): undefined reference to `gcry_sexp_build'
/usr/bin/ld: (.text+0x118): undefined reference to `gcry_pk_verify'
/usr/bin/ld: (.text+0x123): undefined reference to `gcry_sexp_release'
/usr/bin/ld: (.text+0x12d): undefined reference to `gcry_sexp_release'
/usr/bin/ld: (.text+0x166): undefined reference to `gcry_sexp_release'
/usr/bin/ld: /home/martin/dev/rust/xxx/target/debug/deps/liblibssh2_sys-187467b0efb35c13.rlib(libgcrypt.o): in function `_libssh2_dsa_new':
(.text+0x1cc): undefined reference to `gcry_sexp_build'
/usr/bin/ld: (.text+0x203): undefined reference to `gcry_sexp_build'
/usr/bin/ld: /home/martin/dev/rust/xxx/target/debug/deps/liblibssh2_sys-187467b0efb35c13.rlib(libgcrypt.o): in function `_libssh2_rsa_sha1_sign':
(.text+0x73f): undefined reference to `gcry_sexp_build'
/usr/bin/ld: (.text+0x757): undefined reference to `gcry_pk_sign'
/usr/bin/ld: (.text+0x763): undefined reference to `gcry_sexp_release'
/usr/bin/ld: (.text+0x77d): undefined reference to `gcry_sexp_find_token'
/usr/bin/ld: (.text+0x79d): undefined reference to `gcry_sexp_nth_data'
/usr/bin/ld: /home/martin/dev/rust/xxx/target/debug/deps/liblibssh2_sys-187467b0efb35c13.rlib(libgcrypt.o): in function `_libssh2_dsa_sha1_sign':
(.text+0x87c): undefined reference to `gcry_sexp_build'
/usr/bin/ld: (.text+0x896): undefined reference to `gcry_pk_sign'
/usr/bin/ld: (.text+0x8a2): undefined reference to `gcry_sexp_release'
/usr/bin/ld: (.text+0x8d0): undefined reference to `gcry_sexp_find_token'
/usr/bin/ld: (.text+0x8f3): undefined reference to `gcry_sexp_nth_data'
/usr/bin/ld: (.text+0x937): undefined reference to `gcry_sexp_release'
/usr/bin/ld: (.text+0x946): undefined reference to `gcry_sexp_release'
/usr/bin/ld: (.text+0x985): undefined reference to `gcry_sexp_release'
/usr/bin/ld: (.text+0x998): undefined reference to `gcry_sexp_find_token'
/usr/bin/ld: (.text+0x9b2): undefined reference to `gcry_sexp_nth_data'
/usr/bin/ld: /home/martin/dev/rust/xxx/target/debug/deps/liblibssh2_sys-187467b0efb35c13.rlib(libgcrypt.o): in function `_libssh2_dsa_sha1_verify':
(.text+0xa62): undefined reference to `gcry_md_hash_buffer'
/usr/bin/ld: (.text+0xa84): undefined reference to `gcry_sexp_build'
/usr/bin/ld: (.text+0xab2): undefined reference to `gcry_sexp_build'
/usr/bin/ld: (.text+0xac9): undefined reference to `gcry_pk_verify'
/usr/bin/ld: (.text+0xad4): undefined reference to `gcry_sexp_release'
/usr/bin/ld: (.text+0xade): undefined reference to `gcry_sexp_release'
/usr/bin/ld: (.text+0xb16): undefined reference to `gcry_sexp_release'
/usr/bin/ld: /home/martin/dev/rust/xxx/target/debug/deps/liblibssh2_sys-187467b0efb35c13.rlib(libgcrypt.o): in function `_libssh2_cipher_init':
(.text+0xb5a): undefined reference to `gcry_cipher_get_algo_keylen'
/usr/bin/ld: (.text+0xb6c): undefined reference to `gcry_cipher_open'
/usr/bin/ld: (.text+0xb7f): undefined reference to `gcry_cipher_setkey'
/usr/bin/ld: (.text+0xba4): undefined reference to `gcry_cipher_get_algo_blklen'
/usr/bin/ld: (.text+0xbb8): undefined reference to `gcry_cipher_setiv'
/usr/bin/ld: (.text+0xbc5): undefined reference to `gcry_cipher_close'
/usr/bin/ld: (.text+0xbd1): undefined reference to `gcry_cipher_setctr'
/usr/bin/ld: /home/martin/dev/rust/xxx/target/debug/deps/liblibssh2_sys-187467b0efb35c13.rlib(libgcrypt.o): in function `_libssh2_cipher_crypt':
(.text+0xc02): undefined reference to `gcry_cipher_encrypt'
/usr/bin/ld: (.text+0xc11): undefined reference to `gcry_cipher_decrypt'
/usr/bin/ld: /home/martin/dev/rust/xxx/target/debug/deps/liblibssh2_sys-187467b0efb35c13.rlib(global.o): in function `libssh2_init':
(.text+0x38): undefined reference to `gcry_control'
collect2: error: ld returned 1 exit status
I have searched online for answers, but seems like most git2-rs results don't even talk about this, which maybe means I'm missing a -dev dependency or something.
I have seen this and this, but in both cases, there's no setup or any Cargo.toml to peek at.
I have seen the official GitHub repo for git2-rs, and compiled that with a cargo build and it worked.
Have ran these two commands:
$ pkg-config --libs openssl
-lssl -lcrypto
and
$ pkg-config --cflags openssl
^ This one produces no output which I believe is expected.
Where do I look next? My guess is that I am missing a library, or that the version I have is not the same.
I figured this out (after a little bit of experimentation and luck).
The whole issue smelled like a problem with ld and the linking process of the C libssl library needed by git to use SSH connections.
Pop!_OS is known for including a lot of "development needed" things, so I was positive I had all that (I did).
How did I fix it?
I looked at the /etc/ld.so.conf.d/ directory. There are a few ".conf" files there. x86_64-linux-gnu.conf pointed at /usr/lib/x86_64-linux-gnu, so I went there to see which libraries matched libssh*.
I found this:
$ ls -ls /usr/lib/x86_64-linux-gnu/libssh*
312 -rw-r--r-- 1 root root 316732 Sep 5 2019 libssh2.a
0 lrwxrwxrwx 1 root root 16 Sep 5 2019 libssh2.so -> libssh2.so.1.0.1
0 lrwxrwxrwx 1 root root 16 Sep 5 2019 libssh2.so.1 -> libssh2.so.1.0.1
184 -rw-r--r-- 1 root root 186856 Sep 5 2019 libssh2.so.1.0.1
1040 -rw-r--r-- 1 root root 1061468 Dec 10 16:24 libssh.a
0 lrwxrwxrwx 1 root root 22 Dec 10 16:24 libssh-gcrypt.so.4 -> libssh-gcrypt.so.4.8.1
552 -rw-r--r-- 1 root root 564760 Dec 10 16:24 libssh-gcrypt.so.4.8.1
0 lrwxrwxrwx 1 root root 11 Dec 10 16:24 libssh.so -> libssh.so.4
0 lrwxrwxrwx 1 root root 15 Dec 10 16:24 libssh.so.4 -> libssh.so.4.8.1
552 -rw-r--r-- 1 root root 564856 Dec 10 16:24 libssh.so.4.8.1
When comparing this output with a freshly installed VM that does not exhibit this issue, I noticed that all the libssh2* files did not exist in the VM.
Since the linker errors are all in gcry (which I think stands for cryPT), I decided to try removing the two versions and leaving only the one that works:
$ sudo apt remove libssh2-1-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libhttp-parser-dev libmbedtls-dev
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
libgit2-dev libssh2-1-dev
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 3,700 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 412520 files and directories currently installed.)
Removing libgit2-dev:amd64 (0.27.7+dfsg.1-0.2build1) ...
Removing libssh2-1-dev:amd64 (1.8.0-2.1build1) ...
Processing triggers for man-db (2.8.7-3) ...
After doing this, I got the expected output:
$ cargo run
warning: unused variable: `repo`
--> src/main.rs:6:9
|
6 | let repo = match Repository::open("fakerepo") {
| ^^^^ help: consider prefixing with an underscore: `_repo`
|
= note: `#[warn(unused_variables)]` on by default
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `target/debug/xxx`
Hello, world!
thread 'main' panicked at 'Failed to init failed to resolve path 'fakerepo': No such file or directory; class=Os (2); code=NotFound (-3)', src/main.rs:8:19
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
If I initialize a git repo and run it again, there's no error, as expected:
$ mkdir fakerepo; cd fakerepo ; git init ; cd ..
Initialized empty Git repository in /home/martin/dev/rust/xxx/fakerepo/.git/
$ cargo run
warning: unused variable: `repo`
--> src/main.rs:6:9
|
6 | let repo = match Repository::open("fakerepo") {
| ^^^^ help: consider prefixing with an underscore: `_repo`
|
= note: `#[warn(unused_variables)]` on by default
Finished dev [unoptimized + debuginfo] target(s) in 0.03s
Running `target/debug/xxx`
Hello, world!
It appears the issue was that library. I'll investigate further to know where it came from (who installed it) and more importantly, how to make this a non-issue (there's gotta be a way to tell this whole build process which lib to pick), but that's another issue for another day.
What did I do to find this out?
The VM trick, was something that I've done before to solve other issues. Linux is very easy/fast to install on VMs and Gnome Boxes is already installed and configured on my Pop!_OS, so it took me 1 minute to launch it and have a freshly installed OS in front of me (ok, it was not fresh, I had to download like 150 updates in the VM) :)
Anyway, I had a Peppermint OS install; a super light Ubuntu-based distro that doesn't have much in the way, so it was perfect for my needs. All I needed to do on Peppermint OS to get started was:
sudo apt install pkg-config
sudo apt install libssl-dev
sudo apt install curl (yes, it doesn't come with curl)
Install Rust (tl;dr: curl https://sh.rustup.rs -sSf | sh)
After doing this, I was able to run the same hello world project. When I realized it was working on this VM, I did it again on a Pop!_OS 19.10 freshly installed VM too. And again, it worked. (this surprised me, as I was incorrectly blaming "Pop_OS").
The fact that this worked on both VMs with little input from me, prompted me to keep trying on my main machine; I'm glad I did.
I'm trying to compile and run my code on a raspberry pi which needs the snmp libraries. However, I get linking errors such as "undefined reference to 'EVP_DigestUpdate'".
I've been researching this issue for the past few days and found out that this usually happens when snmp can't find the ssl library crypto, for example if you don't specify -lcrypto before -lsnmp when linking your object, or when the linker just can't can't find -lcrypto.
However, on my raspberry pi I have all required libraries in /usr/lib/gcc/arm-linux-gnueabihf.
This is how I installed the libraries:
apt-get install libssl-dev libsnmp-dev libsnmp-base libsnmp30
I generate trap.o with this command:
gcc -c -g -pedantic -Wall -Wshadow -I/home/pi/tests/h -I/usr/include trap.c -o trap.o
I link trap.o the libraries with this command:
gcc -static -g -pedantic -Wall -Wshadow trap.o -o trap -L/usr/lib/arm-linux-gnueabihf/lib -lcrypto -lpthread -lnetsnmpagent -lnetsnmpmibs -lnetsnmphelpers -lnetsnmp
And then I get this error:
gcc -static -g -pedantic -Wall -Wshadow trap.o -o trap -L/usr/lib/arm-linux-gnueabihf/lib -lcrypto -lpthread -lnetsnmpagent -lnetsnmpmibs -lnetsnmphelpers -lnetsnmp
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(system.o): In function `netsnmp_str_to_gid':
(.text+0x1144): warning: Using 'getgrnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(system.o): In function `netsnmp_str_to_gid':
(.text+0x1154): warning: Using 'endgrent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(system.o): In function `netsnmp_str_to_uid':
(.text+0x10d8): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(system.o): In function `netsnmp_str_to_uid':
(.text+0x10e8): warning: Using 'endpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(system.o): In function `netsnmp_getaddrinfo':
(.text+0x4a4): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(system.o): In function `netsnmp_gethostbyaddr':
(.text+0x9f8): warning: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
trap.o: In function `parse_address':
/home/pi/tests/trap.c:56: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/crt1.o: In function `_start':
/build/glibc-6f8a9a/glibc-2.19/csu/../ports/sysdeps/arm/start.S:119: undefined reference to `main'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_random':
(.text+0x168): undefined reference to `RAND_bytes'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_generate_keyed_hash':
(.text+0x290): undefined reference to `EVP_md5'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_generate_keyed_hash':
(.text+0x2b4): undefined reference to `HMAC'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_generate_keyed_hash':
(.text+0x33c): undefined reference to `EVP_sha1'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_hash':
(.text+0x424): undefined reference to `EVP_sha1'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_hash':
(.text+0x42c): undefined reference to `EVP_MD_CTX_create'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_hash':
(.text+0x438): undefined reference to `EVP_DigestInit'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_hash':
(.text+0x448): undefined reference to `EVP_DigestUpdate'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_hash':
(.text+0x458): undefined reference to `EVP_DigestFinal'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_hash':
(.text+0x468): undefined reference to `EVP_MD_CTX_destroy'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_hash':
(.text+0x488): undefined reference to `EVP_md5'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_encrypt':
(.text+0x86c): undefined reference to `DES_key_sched'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_encrypt':
(.text+0x8a0): undefined reference to `DES_ncbc_encrypt'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_encrypt':
(.text+0x8c4): undefined reference to `DES_ncbc_encrypt'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_encrypt':
(.text+0x90c): undefined reference to `AES_set_encrypt_key'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_encrypt':
(.text+0x948): undefined reference to `AES_cfb128_encrypt'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_encrypt':
(.text+0xa74): undefined reference to `DES_key_sched'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_encrypt':
(.text+0xaac): undefined reference to `DES_ncbc_encrypt'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_decrypt':
(.text+0xc78): undefined reference to `AES_set_encrypt_key'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_decrypt':
(.text+0xcb0): undefined reference to `AES_cfb128_encrypt'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_decrypt':
(.text+0xd9c): undefined reference to `DES_key_sched'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(scapi.o): In function `sc_decrypt':
(.text+0xdd0): undefined reference to `DES_cbc_encrypt'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(keytools.o): In function `generate_Ku':
(.text+0x74): undefined reference to `EVP_MD_CTX_create'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(keytools.o): In function `generate_Ku':
(.text+0x98): undefined reference to `EVP_md5'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(keytools.o): In function `generate_Ku':
(.text+0xa4): undefined reference to `EVP_DigestInit'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(keytools.o): In function `generate_Ku':
(.text+0xe8): undefined reference to `EVP_DigestUpdate'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(keytools.o): In function `generate_Ku':
(.text+0x10c): undefined reference to `EVP_DigestFinal'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(keytools.o): In function `generate_Ku':
(.text+0x138): undefined reference to `EVP_MD_CTX_destroy'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(keytools.o): In function `generate_Ku':
(.text+0x178): undefined reference to `EVP_sha1'
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/libnetsnmp.a(keytools.o): In function `generate_Ku':
(.text+0x184): undefined reference to `EVP_DigestInit'
collect2: error: ld returned 1 exit status
Could it be that the issue is being caused because the snmp libraries I installed were built using a different openssl version than the ones I have in my environment? My libssl-dev and libsnmp-dev versions are the following:
dpkg -l | grep libssl-dev:
ii libssl-dev:armhf 1.0.1k-3+deb8u5 armhf Secure Sockets Layer toolkit - development files
dpkg -l | grep libsnmp-dev:
ii libsnmp-dev 5.7.2.1+dfsg-1 armhf SNMP (Simple Network Management Protocol) development files
Any help would be appreciated,
Thanks
All of your undefined references are in libnetsnmp and they are all undefined
references to functions defined in libcypto. This happens because -lcrypto
precedes -lnetsnmp in your linkage.
In the linkage sequence, files that need symbol definitions must occur
before the ones that provide the definitions, because the linker by default will
only search a library to find definitions of symbols that it has
observed to be referenced, but not defined, in earlier files. (You appear to
have mis-learned this rule, the wrong way round). From man ld:
The linker will search an archive only once, at the location where
it is specified on the command line. If the archive defines a
symbol which was undefined in some object which appeared before the
archive on the command line, the linker will include the
appropriate file(s) from the archive. However, an undefined symbol
in an object appearing later on the command line will not cause the
linker to search the archive again.
So link -lcrypto after -lnetsnmp.
I am trying to compile a v4l2 example in Ubuntu but I am getting the following error:
guilherme#notedev01:~/Downloads/V4l2_samples-0.4.1$ make
gcc -O2 -L/usr/include -lX11 -lXext -o viewer viewer.c
/tmp/ccUjnjWQ.o: In function `image_destroy':
viewer.c:(.text+0x234): undefined reference to `XDestroyImage'
viewer.c:(.text+0x256): undefined reference to `XFreeGC'
viewer.c:(.text+0x277): undefined reference to `XShmDetach'
viewer.c:(.text+0x2ac): undefined reference to `XFreePixmap'
/tmp/ccUjnjWQ.o: In function `image_create':
viewer.c:(.text+0x305): undefined reference to `XCreateGC'
viewer.c:(.text+0x31d): undefined reference to `XGetWindowAttributes'
viewer.c:(.text+0x39e): undefined reference to `XShmCreateImage'
viewer.c:(.text+0x3f5): undefined reference to `XShmAttach'
viewer.c:(.text+0x44e): undefined reference to `XCreateImage'
viewer.c:(.text+0x494): undefined reference to `XShmQueryExtension'
viewer.c:(.text+0x4b4): undefined reference to `XShmPixmapFormat'
viewer.c:(.text+0x4dc): undefined reference to `XShmCreatePixmap'
/tmp/ccUjnjWQ.o: In function `image_put':
viewer.c:(.text+0x54c): undefined reference to `XPutImage'
viewer.c:(.text+0x586): undefined reference to `XShmPutImage'
/tmp/ccUjnjWQ.o: In function `main':
viewer.c:(.text.startup+0x18b): undefined reference to `XOpenDisplay'
viewer.c:(.text.startup+0x1b1): undefined reference to `XScreenOfDisplay'
viewer.c:(.text.startup+0x1ee): undefined reference to `XCreateSimpleWindow'
viewer.c:(.text.startup+0x249): undefined reference to `XMapRaised'
viewer.c:(.text.startup+0x263): undefined reference to `XStoreName'
viewer.c:(.text.startup+0x280): undefined reference to `XGetWindowAttributes'
viewer.c:(.text.startup+0x92f): undefined reference to `XPending'
viewer.c:(.text.startup+0x94c): undefined reference to `XNextEvent'
viewer.c:(.text.startup+0xaee): undefined reference to `XPending'
viewer.c:(.text.startup+0xb0b): undefined reference to `XNextEvent'
viewer.c:(.text.startup+0xf39): undefined reference to `XPending'
viewer.c:(.text.startup+0xf56): undefined reference to `XNextEvent'
collect2: error: ld returned 1 exit status
make: *** [viewer] Error 1
What I can see is that the path for -lx11 and -lXext isn't -L/usr/include.
How can I find the right path for those libraries?
Thanks.
as Chris has pointed out, the order is wrong, you need to put the -lX11 -lXext after the source-code/object-files.
this is because modern compilers try to optimize the final result and not link against unused libraries.
they do so by maintaining a list of unresolved symbols within an object and use any binary files that come aferwards in the linker arguments to resolve those symbols.
example
your program test uses the function do_foo() from libfoo and the function do_bar_do() from libbar.
you link it using:
$ gcc -o test test.o -lfoo -lbar
the linker first searches test.o and notices that some symbols (do_foo and do_bar_do) are not defined anywhere. it then proceeds to libfoo (specified right after test.o) and finds that it provides do_foo, so it creates code to use it from your program. do_bar_do is still unresolved, until the linker checks upon libbar.
consider doing it the wrong way:
$ gcc -o test -lfoo test.o -lbar
the linker will first check libfoo and see that it doesn't contain any unresolved symbols. cool. it will then proceed to test.o and notice do_bar_do and do_foo. do_bar_do is resolved by the right-hand libbar but do_foo is not resolved at all, and you get an error:
undefined reference to `do_foo'
"but the code is meant to be a tutorial..."
so why is it not working?
older compilers where a bit lax about the order of dependencies (they would check all binaries/libraries/objects whether a given symbol could be resolved); that's why you can still find code out there that puts the libraries to link against before the object files.
The -lX11 -lXext must come after the viewer.c in the command line (and should probably be in the order -lXext -lX11). Also, ensure that the libx11-6-dev and libxext6-dev packages are installed.
System libraries are usually in /lib and /usr/lib, and you do not need to use -L to specify those directories.
I'm trying to follow this introductory tutorial on jack (audio server for linux). In the tutorial, the author explains that you should use pkg-config to find the cflags and libs for jack, making the gcc command like this:
gcc -o simple_client `pkg-config --cflags --libs jack` simple_client.c
which gives the output:
/tmp/ccyuOC0u.o: In function `signal_handler':
simple_client.c:(.text+0x16): undefined reference to `jack_client_close'
/tmp/ccyuOC0u.o: In function `process':
simple_client.c:(.text+0x6f): undefined reference to `jack_port_get_buffer'
simple_client.c:(.text+0x87): undefined reference to `jack_port_get_buffer'
/tmp/ccyuOC0u.o: In function `main':
simple_client.c:(.text+0x25b): undefined reference to `sin'
simple_client.c:(.text+0x2c1): undefined reference to `jack_client_open'
simple_client.c:(.text+0x372): undefined reference to `jack_get_client_name'
simple_client.c:(.text+0x3b1): undefined reference to `jack_set_process_callback'
simple_client.c:(.text+0x3ca): undefined reference to `jack_on_shutdown'
simple_client.c:(.text+0x3ee): undefined reference to `jack_port_register'
simple_client.c:(.text+0x419): undefined reference to `jack_port_register'
simple_client.c:(.text+0x475): undefined reference to `jack_activate'
simple_client.c:(.text+0x4c5): undefined reference to `jack_get_ports'
simple_client.c:(.text+0x514): undefined reference to `jack_port_name'
simple_client.c:(.text+0x52c): undefined reference to `jack_connect'
simple_client.c:(.text+0x56e): undefined reference to `jack_port_name'
simple_client.c:(.text+0x586): undefined reference to `jack_connect'
simple_client.c:(.text+0x5ba): undefined reference to `jack_free'
collect2: ld returned 1 exit status
I'm not very experienced using gcc or writing c programs generally (most of my experience has been with javascript, clojure, java, python, and php). What I gather from this and my research into it is that some libraries are missing or linked incorrectly (not sure which).
So just running pkg-config --cflags --libs jack on my machine, I get:
-ljack
In the tutorial referenced above, the author demonstrates the same method for gleaning the libs to be linked for jack, but his output looks like this:
-ljack -lpthread -ldl -lrt
Not sure what pthread is, but I think dl is dsp-loader, and rt has something to do with realtime. I've searched in several directories called /lib and haven't come across anything for these other libs, so I don't think they exist on my machine. However, it seems strange to me that calling pkg-config doesn't make any mention of them. How should I go about finding these libs? Or am I on the wrong track?
Your link command line is wrong, try this one instead:
gcc -o simple_client simple_client.c `pkg-config --cflags --libs jack`
The order of archive libraries on command line matters.