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

Rustc doesn't link c++ std lib #44926

Closed
shayanjm opened this issue Sep 29, 2017 · 5 comments
Closed

Rustc doesn't link c++ std lib #44926

shayanjm opened this issue Sep 29, 2017 · 5 comments

Comments

@shayanjm
Copy link

shayanjm commented Sep 29, 2017

I am currently trying to work with https://github.com/flier/rust-hyperscan. I recently updated cargo via rustup and started noticing that my code breaks when run.

I am currently running MacOS 10.12.6 and rustc 1.20.0

This is a contrived example, mostly from the upstream "rust-hyperscan" project, which includes the output error I'm seeing when I runcargo clean && cargo test: https://gist.github.com/shayanjm/aa7a9ebb0bddd1beb8ec4f3d3f87463b

On L80 of build.rs (https://gist.github.com/shayanjm/aa7a9ebb0bddd1beb8ec4f3d3f87463b#file-build-rs-L80) I've verified that the println! runs as expected by changing c++ to something I know would break and retrying cargo clean && cargo test.

I've also verified that libc++ has the symbols in question via nm -gU /usr/lib/libc++dylib | grep dynamic, which returned 0000000000018c54 I ___dynamic_cast (the first "undefined symbol" in the error)

Is this an issue with the way rustc is linking the c++ std lib? Or have I done something wrong?

@steveklabnik
Copy link
Member

This doesn't feel like a rustc bug to me, or at least, there's too much going on here to really determine it. As such, I would suggest posting to https://users.rust-lang.org/, which is better for these kinds of questions. We try to keep the issue tracker for bugs only.

If you can reduce this to a small example demonstrating that it's a rustc bug, then we can re-open, but until then, I'm going to give this a close. Thank you!

@valpackett
Copy link
Contributor

Maybe this isn't the problem on your machine, but in the build.rs script, libc++ must be printed last. It's a really weird issue, I've just encountered this while fixing mozjs to build on FreeBSD. Somehow no one encountered it with mozjs on other platforms o_0 But this is mentioned in a ton of StackOverflow answers about C++ linking problems (without Rust!).

Trying to build rust-hyperscan on FreeBSD (after fixing build.rs):

note: /usr/bin/ld: /usr/home/greg/src/github.com/flier/rust-hyperscan/target/debug/deps/libhyperscan-9d582c0a3986e7c0.rlib(runtime.c.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
          /usr/home/greg/src/github.com/flier/rust-hyperscan/target/debug/deps/libhyperscan-9d582c0a3986e7c0.rlib: could not read symbols: Bad value
          cc: error: linker command failed with exit code 1 (use -v to see invocation)

— fixed that by, well, recompiling the system hyperscan with -fPIC :)

@shayanjm
Copy link
Author

shayanjm commented Oct 4, 2017

@myfreeweb unfortunately this didn't fix the build on my machine :(

@retep998
Copy link
Member

retep998 commented Oct 4, 2017

Based on a conversation on IRC, it appears this issue was resolved by switching from kind=static to kind=dylib. Really this is just yet another reason we should either change the behavior of kind=static or stabilize kind=static-nobundle and heavily deprecate kind=static.

@shayanjm
Copy link
Author

shayanjm commented Oct 4, 2017

@retep998 +1 - I'll also be creating a PR to the upstream rust-hyperscan project to fix this. Thanks everyone for your help!

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

4 participants