Linker error when compiling on Darwin


I’m trying to compile a project which consumes rust-zmq. It compiles fine on Fedora, CentOS and Ubuntu, but won’t compile on OS X or FreeBSD. When I run cargo build I get:

note: /usr/bin/ld: cannot find -lzmq

ZeroMQ is installed and the header file is in /usr/local/include.

I’ve tried modifying Cargo.toml as suggested on Reddit but haven’t got anywhere. My changes are:

links = "zmq"
build = ""

rustc-link-search = ["/usr/local/include"]
rustc-link-lib = ["zmq"]

This doesn’t make a scrap of difference to the error I’m getting and “/usr/local/include” doesn’t seem to be added to the linker args as it’s supposed to (??). Note that is blank. I only included it at all because Cargo complained when I didn’t have it specified.

Could it be that OS X and FreeBSD both use Clang while Linux uses GNU?

I’d really appreciate a hand!



Quick update to this - the linker seems to be looking in /rust/proj/lib/x86_64-unknown-freebsd amongst other directories. I tested adding a symlink from that directory to /usr/local/lib and it compiled without complaint. I really don’t want to have to do that! Is there a way to resolve this within Cargo?

Also I realise now that /usr/local/include is the wrong directory. Pretend I said /usr/local/lib! :smile:


‘include’ is where include files for ZeroMQ are located. And Rust doesn’t understand C headers on its own. You need to check where is located, and add appropriate libpath via -L flag, or its analog.
Exempt from my cargo:rustc-link-search=native=./lib
Maybe you need rustc-link-search = [ "native=/usr/local/lib" ]


Cheers for the help mate. Putting stuff in Cargo.toml didn’t work for me, but I used your excerpt and that worked.