3

I installed libportaudio using Homebrew on OS X. The install succeeded and I verified there were symlinks to the actual headers and libraries in /usr/local/include and /usr/local/lib.

However, I am now trying to make a Rustlang binding (https://github.com/JeremyLetang/rust-portaudio) that uses the libraries. It fails with the following error:

error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-o' 'target/libportaudio.dylib' 'target/portaudio.o' '-Wl,-force_load,/usr/local/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a' 'target/portaudio.metadata.o' '-nodefaultlibs' '-fno-lto' '-Wl,-dead_strip' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lstd-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lsync-4e7c5e5c' '-L' '/usr/local/lib/rustlib/x86_64-apple-darwin/lib' '-lrustrt-4e7c5e5c' '-L' 'target/deps' '-L' '/Users/drasa/repo/rust-portaudio/.rust' '-L' '/Users/drasa/repo/rust-portaudio' '-lportaudio' '-lSystem' '-lpthread' '-lc' '-lm' '-dynamiclib' '-Wl,-dylib' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Users/drasa/repo/rust-portaudio/.rust'
ld: library not found for -lportaudio
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error

So, it seems that cc doesn't search libraries from prefix /usr/local. Is this supposed to be so? How can I change that? Are homebrew-installed libraries supposed to work out of the box?

2 Answers2

2

I resolved this by setting

export LIBRARY_PATH="/usr/local/lib"

After LIBRARY_PATH is set, Cargo builds rust-portaudio without a hitch too.

1

Apparently, rustc calls the system cc for linking, and it is not set up to look into /usr/local/lib/ for libraries. This is arguably the fault of the Homebrew rust package. (It does appear to look for header files under /usr/local/.)

Alternatively, the rust-portaudio package could use pkg-config to locate portaudio.

I was able to let it build further by running

make COMPILER='rustc -L/usr/local/lib'

but then it runs into other errors that I don't understand.