erickt / rust-zmq

Rust zeromq bindings.
Apache License 2.0
887 stars 190 forks source link

Undefined reference to `zmq_has', after installing correct bindings for Debian Jessie #207

Closed msm-code closed 5 years ago

msm-code commented 6 years ago

What I did:

Installed clean Debian Jessie, needed packages and recommended zmq bindings

apt install libzmq3-dev

And:

cargo build --release

And:

root@osboxes:/home/osboxes/ursadb# ~/.cargo/bin/cargo build --release
   Compiling zmq v0.8.2
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/osboxes/ursadb/target/release/build/zmq-711f9aefae80083c/build_script_build-711f9aefae80083c.build_script_build0.rcgu.o" "-o" "/home/osboxes/ursadb/target/release/build/zmq-711f9aefae80083c/build_script_build-711f9aefae80083c" "/home/osboxes/ursadb/target/release/build/zmq-711f9aefae80083c/build_script_build-711f9aefae80083c.crate.allocator.rcgu.o" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-nodefaultlibs" "-L" "/home/osboxes/ursadb/target/release/deps" "-L" "/usr/lib/x86_64-linux-gnu" "-L" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/osboxes/ursadb/target/release/deps/libzmq_sys-a8aa15e613cdba62.rlib" "/home/osboxes/ursadb/target/release/deps/liblibc-cb2df4011e20c9ce.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-cc8b303e3403a89b.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-7ea6f64ea02051fd.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-f1fba9b54042d271.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-46a427bcbb71fa34.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_system-afe41ccc67b2a14a.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-aac5870ffe4fa74c.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-6a8e7eff29b6cad2.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_unicode-a768e53a3f571290.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-016e6e96bb6127b9.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-f2b084cc7a7d8bb1.rlib" "-Wl,-Bdynamic" "-l" "zmq" "-l" "util" "-l" "dl" "-l" "rt" "-l" "pthread" "-l" "pthread" "-l" "gcc_s" "-l" "c" "-l" "m" "-l" "rt" "-l" "pthread" "-l" "util" "-l" "util"
  = note: /home/osboxes/ursadb/target/release/build/zmq-711f9aefae80083c/build_script_build-711f9aefae80083c.build_script_build0.rcgu.o: In function `build_script_build::main::ha5cc5cd5a08c4033':
          build_script_build0-5ea246a54410eb6924d72faee8e217fe.rs:(.text._ZN18build_script_build4main17ha5cc5cd5a08c4033E+0x9a): undefined reference to `zmq_has'
          collect2: error: ld returned 1 exit status

I thought that libzmq3-dev should be good for rust-zmq?

rotty commented 6 years ago

Yes, the version in Debian jessie (4.0.5) should be new enough. Regarding your linker failure: there is code in the build.rs script that should check wether the libzmq used supports zmq_has, and if it does not, the rest of the codebase tries to work around that (grep for ZMQ_HAS_ZMQ_HAS to see what I mean). I'll try to setup a jessie environment and reproduce your issue locally.

rotty commented 6 years ago

Could you try building with cargo build --no-default-features? This is required for building against zmq versions before 4.1. I will update the documentation accordingly.

Unfortunately, it seems to be impossible to auto-detect that, as that would require being able to call zmq_has from build.rs if libzmq is new enough, without a link-time dependency on zmq_has. On second thought, it might even be possible, but would require using something like dlopen to obtain a function pointer to zmq_has. This approach is not portable across operating systems, and probably would be quite a bit more hassle than it's worth.

tinyplasticgreyknight commented 6 years ago

I have the same problem, also on Jessie. I tried with cargo build --no-default-features but I get the same error message (build.rs:8: undefined reference to 'zmq_has')

The offending build script line is inside a function marked with #[cfg(feature = "zmq_has")] so I assume that cfg is misreporting somehow. I experimentally forced the issue in a local copy by straight-up removing the zmq_has version of main there, and the project built successfully.

evgeniy-scherbina commented 5 years ago

Same issue Ubuntu 14:04

vsraptor commented 5 years ago

is there a solution to this problem .....

thedavidmeister commented 5 years ago

seeing the same issue on nixos

thedavidmeister commented 5 years ago

seems resolved in latest commit?

stavinsky commented 5 years ago

same issue on centos7. rust-zmq==0.8

thedavidmeister commented 5 years ago

what is stopping rust-zmq rolling a new release with the fix in it?

stavinsky commented 5 years ago

actually I tried 4.2.5 and it works fine. But for now i have similar problem on windows.

thedavidmeister commented 5 years ago

yeah i think we were seeing windows issues too

rotty commented 5 years ago

I've just now published 0.8.3, which contains the commit that should fix this issue. Can someone on an ancient distro verify?

thedavidmeister commented 5 years ago

we stopped using zmq soz

rotty commented 5 years ago

Given this was only an issue with libzmq versions older that what's required for the latest release of zmq (i.e., 0.9.0), and that it should be fixed in 0.8.3, I'm going to close this issue. Feel free to reopen should you encounter this issue in 0.8.3.

gilescope commented 3 years ago

Datapoint: alas am stuck on zmq 3.4. I can confirm it is still an issue on 0.8.3 with ubuntu 16 on wsl2