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

Can't compile even though portaudio is installed #130

Open
programLyrique opened this issue Mar 23, 2016 · 10 comments
Open

Can't compile even though portaudio is installed #130

programLyrique opened this issue Mar 23, 2016 · 10 comments

Comments

@programLyrique
Copy link

I'm using Mac OS.

I have added portaudio as a dependency in a project and I have the following error, both when using version 0.6.3 from crates.io and and from the git master:

Compiling portaudio v0.6.3 (https://github.com/RustAudio/rust-portaudio.git#dc1f284f)
error: could not find native static library `portaudio`, perhaps an -L flag is missing?
Could not compile `portaudio`.

However, I have installed portaudio with port:

$ ls /opt/local/lib | grep portaudio
libportaudio.2.dylib
libportaudio.a
libportaudio.dylib
libportaudiocpp.0.dylib
libportaudiocpp.a
libportaudiocpp.dylib

I have added it to the library path:

$ echo $LIBRARY_PATH
/opt/local/lib/

I have also tried cargo rustc -- -L/opt/local/bin/ without success... apparently, the flags added for rustc are not used to compile dependencies.

I have also tried to install portaudio with Homebrew (so that it is in the more usual location, in /usr/local/lib/) but it doesn't work either.

Anyway, shouldn't the build process download portaudio and compile it if it is not found?

@programLyrique programLyrique changed the title Cant' compile even though portaudio is installed Can't compile even though portaudio is installed Mar 23, 2016
@limeburst
Copy link
Contributor

Have you tried cargo clean after installing portaudio, and before compiling?

@pepyakin
Copy link

Same here, even after cargo clean.

@programLyrique
Copy link
Author

I am now using version 0.6.4 and it works flawlessly.

@RobAber
Copy link

RobAber commented Jul 12, 2016

I had a build issue with the same error as listed above. I think I have tracked down the problem and have a workaround. I'm on a few days old, clean install of macOS 10.11.5. I don't have ports or brew installed. I'm running the current beta of Xcode.

The stable version of PortAudio won't build on my setup, so I went with the daily snapshot from July 11. This builds fine on my system and I installed it under /usr/local. The 0.6.4 version of rust-portaudio fails to build against this setup with the error generated in the original parent issue.

I did some poking around and it looked to me like the build was always trying to do a static build no matter what settings and environment vars I supplied. I then discovered that if I commented out the "if pkg_config::Config::new:: ..." section in build.rs, the build worked fine. So, I checked out pkg-config-rs and did a build of it. The build completes successfully but the tests fail. I discovered that this is caused by the fact that I didn't have the pkg-config program installed on my system.

The fix: I downloaded pkg-config latest from https://pkg-config.freedesktop.org/releases/ and built and installed with a configuration of,
./configure --prefix=/usr/local --with-internal-glib

I then did a clean clone of rust-portaudio and ran cargo build and cargo test with no issues. All of the example programs run as they are supposed to.

@rap2hpoutre
Copy link
Contributor

rap2hpoutre commented Aug 9, 2016

Similar problem. Running on mac OSX 10.11.5. portaudio is installed (/usr/local/lib/). I just tried tu run examples: cargo run --example sine.

I use version 0.7.0 and it works removing if pkg_config::Config::... and leaving the return inside.

@mitchmindtree
Copy link
Member

Thanks a lot everyone, I'll leave this open until a fix for the build.rs script lands. I won't have time to do this myself for a little while yet, so if anyone is considering making the fix feel free to open a PR.

@rap2hpoutre
Copy link
Contributor

if anyone is considering making the fix feel free to open a PR

The "fix" I tried is not really a fix, it's a quick workaround. I replaced this:

if pkg_config::Config::new().atleast_version("19").find("portaudio-2.0").is_ok() {
    return;
}

With:

// if pkg_config::Config::new().atleast_version("19").find("portaudio-2.0").is_ok() {
    return; // <- return is still here
// }

I'm not sure it's what you want. Should we do something conditional like cfg!(target_os = "macos")?

@rap2hpoutre
Copy link
Contributor

rap2hpoutre commented Aug 11, 2016

I found a solution. Just run brew install pkg-config too (and cargo clean if you have some mess). I will send a PR for readme.

rap2hpoutre added a commit to rap2hpoutre/rust-portaudio that referenced this issue Aug 11, 2016
Installation information for Mac users (RustAudio#130)
@RobAber
Copy link

RobAber commented Aug 11, 2016

Yeah, I also feel that any fix here should just be in the readme and mention how to install pkg-config. The real problem seems to me to be in pkg-config-rs, so perhaps an issue needs to be opened there too.

@ConnorGray
Copy link

ConnorGray commented May 4, 2017

I've just tried this locally on my machine, and I noticed a small issue. I'm on a fairly fresh machine that didn't previously have PortAudio installed, and am using rust-portaudio 0.7.0.

I initially ran cargo build and got the standard "error: could not find native static library portaudio, perhaps an -L flag is missing?" message. I then did brew install portaudio && brew install pkg-config. Trying cargo build again led to the same error message.

At first I thought there must be something wrong with the build script or environment (which is what led me to this thread). However, after some experimenting, I determined that if I closed my terminal and reopened it, and then re-ran cargo build, things worked as expected.

I'm not sure what the issue exactly was though. Perhaps something to do with a environment variable brew sets? Can anyone reproduce it/any ideas?

It seems I forgot to cargo clean in between installing portaudio and rebuilding. It might be useful to add a comment to the README saying this is necessary if you've failed to build once.

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

7 participants