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

Undefined reference to __rust_dealloc/ __rust_alloc when crate-type is ["staticlib", "dylib"] #56784

Closed
mosyp opened this issue Dec 13, 2018 · 3 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example

Comments

@mosyp
Copy link

mosyp commented Dec 13, 2018

Problem
A part of Cargo.toml:

[lib]
name = "my_lib"
crate-type = ["rlib", "staticlib", "dylib"]

When I build these rust artifact and try to link to it within c program I get a lot of undefined reference to '__rust_dealloc' / '__rust_alloc'. For example, the output of :

/usr/bin/ld: libmy_lib.a(std-52f862a21e09568c.std.6as1l5rw-cgu.0.rcgu.o): in function `alloc::alloc::alloc':
/rustc/abe02cefd6cd1916df62ad7dc80161bea50b72e8/src/liballoc/alloc.rs:78: undefined reference to `__rust_alloc'
/usr/bin/ld: libmy_lib.a(std-52f862a21e09568c.std.6as1l5rw-cgu.0.rcgu.o): in function `alloc::alloc::dealloc':
/rustc/abe02cefd6cd1916df62ad7dc80161bea50b72e8/src/liballoc/alloc.rs:96: undefined reference to `__rust_dealloc'
/usr/bin/ld: /rustc/abe02cefd6cd1916df62ad7dc80161bea50b72e8/src/liballoc/alloc.rs:96: undefined reference to `__rust_dealloc'

Compiling c code as gcc main.c my_lib.a -lm -ldl ....

But once I remove a dylib from Cargo.toml, it complies correctly with a success

Notes

Actually I don't need "dylib" for a linux development, but do need for windows. However I couldn't do something like [target.'cfg(windows)'.lib] (as for dependencies)

Output of cargo version:

cargo 1.31.0 (339d9f9c8 2018-11-16)

@alexcrichton alexcrichton transferred this issue from rust-lang/cargo Dec 13, 2018
@alexcrichton
Copy link
Member

Thanks for the report! I transferred this to the rust-lang/rust repository as this is a compiler bug rather than a Cargo bug, but perhaps you intended to have the cdylib crate type instead of the dylib crate type?

@jonas-schievink jonas-schievink added the A-linkage Area: linking into static, shared libraries and binaries label Jan 26, 2019
@bjorn3 bjorn3 added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Jul 29, 2023
@bjorn3
Copy link
Member

bjorn3 commented Jul 29, 2023

Can you provide an MCVE for this issue? Parts of rustc are built as dylib, so this should work just fine.

@jackh726
Copy link
Member

Closing since I think this will be very hard (if not impossible) to reproduce without some code to start from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
Projects
None yet
Development

No branches or pull requests

5 participants