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

Issue linking dynamic libraries #155

Closed
sga001 opened this issue Apr 24, 2017 · 3 comments
Closed

Issue linking dynamic libraries #155

sga001 opened this issue Apr 24, 2017 · 3 comments

Comments

@sga001
Copy link

sga001 commented Apr 24, 2017

Hello,

I'm having issues linking to dynamic libraries. Not sure if the problem is with rust's FFI, this crate, my system's gcc, or something else entirely.

In rust, when I declare the extern block I add
#[link(name="libname")] but I get linking issues. If I instead add #[link(name="libname", kind="static")] everything works fine. I created a super simple toy example to show this. I also tested compiling and linking against the dynamic library using g++ as: g++ <file.cpp> -l<libname> and it works fine.

The code is available at: https://github.com/sga001/rust-linking-issue

My gcc/g++ is version 6.3.1. I'm using Arch Linux 4.9.11. Rustc version 1.18.0-nightly (2bd4b5c6d 2017-04-23).

Thanks!

@alexcrichton
Copy link
Member

Oh typically you'll want to mange this through the build script rather than the crate itself. It looks like this is related to linking the boost runtime? If the static version can be located but the dynamic version can't that may mean you need an extra -L path somewhere, or that the linkage to boost needs to be tweaked.

Can you gist the error messages you're seeing?

@sga001
Copy link
Author

sga001 commented Apr 24, 2017

Hmmm... I should probably mention this only happens in recent nightly versions (my app used to work a few weeks ago and just recently stopped working).

I just tested:

rustc 1.18.0-nightly (2564711e8 2017-04-04) works fine.
rustc 1.18.0-nightly (91ae22a01 2017-04-05) works fine.
rustc 1.18.0-nightly (50c186419 2017-04-06) does not work.
rustc 1.18.0-nightly (53f4bc311 2017-04-07) does not work.
rustc 1.18.0-nightly (ad36c2f55 2017-04-09) does not work.
rustc 1.18.0-nightly (2bd4b5c6d 2017-04-23) does not work.

So maybe this is due to some recent change in rustc/cargo?

Here's the gist.
https://gist.github.com/sga001/c6031a9f4c4756f97cdf025f433fcbbe

Note that this is not just about Boost. I used boost in the toy example because that's a common library. In my actual application this happens with boost, mpfr, gmp, and gomp (basically all libraries that I'm dynamically linking).

Also both the dynamic and static versions of boost (for the example) are in /usr/lib/, so I don't think this is a path issue.

Thanks

@alexcrichton
Copy link
Member

Hm I can't think of a change that'd affect this, but it'd be good to narrow in on the changes!

This looks like it may not be a gcc-rs issue regardless, but rather a configuration or rustc/cargo issue

@sga001 sga001 closed this as completed May 4, 2017
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

2 participants