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

rust bin do not support static and dynamic library #51600

Closed
VikingMew opened this issue Jun 16, 2018 · 4 comments
Closed

rust bin do not support static and dynamic library #51600

VikingMew opened this issue Jun 16, 2018 · 4 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries

Comments

@VikingMew
Copy link

VikingMew commented Jun 16, 2018

ref from the top answer of
https://stackoverflow.com/questions/26946646/rust-package-with-both-a-library-and-a-binary

this sample works fine, but it is not working when crate-type = ["staticlib"] is added into [lib]

     Running `rustc --crate-name mylib src/lib.rs --crate-type staticlib --emit=dep-info,link -C debuginfo=2 -C metadata=f36b9f5bc9ab9f55 -C extra-filename=-f36b9f5bc9ab9f55 --out-dir D:\cargo_temp\temp1\target\debug\deps -C incremental=D:\cargo_temp\temp1\target\debug\incremental -L dependency=D:\cargo_temp\temp1\target\debug\deps`
     Running `rustc --crate-name mybin src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=2687d511ce54ac88 -C extra-filename=-2687d511ce54ac88 --out-dir D:\cargo_temp\temp1\target\debug\deps -C incremental=D:\cargo_temp\temp1\target\debug\incremental -L dependency=D:\cargo_temp\temp1\target\debug\deps`
error[E0463]: can't find crate for `mylib`
 --> src/main.rs:1:1
  |
1 | extern crate mylib;
  | ^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

cargo ver: cargo 1.28.0-nightly (c3b09c968 2018-05-27)
rust ver: rustc 1.28.0-nightly (5bf68db 2018-05-28)

@jonas-schievink
Copy link
Contributor

See https://doc.rust-lang.org/reference/linkage.html

Rust crates cannot link against staticlibs. You need to add rlib to the crate types.

@VikingMew
Copy link
Author

is that possible to link as dylib, or lib is the only supported form?

I met error with dylib

 Running `rustc --crate-name mybin src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=83480335185a07f8 -C extra-filename=-83480335185a07f8 --out-dir D:\cargo_temp\temp1\target\debug\deps -C incremental=D:\cargo_temp\temp1\target\debug\incremental -L dependency=D:\cargo_temp\temp1\target\debug\deps --extern mylib=D:\cargo_temp\temp1\target\debug\deps\mylib.dll`
error: cannot satisfy dependencies so `std` only shows up once
  |
  = help: having upstream crates all available in one format will likely make this go away

error: cannot satisfy dependencies so `core` only shows up once
  |
  = help: having upstream crates all available in one format will likely make this go away

error: cannot satisfy dependencies so `compiler_builtins` only shows up once
  |
  = help: having upstream crates all available in one format will likely make this go away

@jonas-schievink
Copy link
Contributor

That looks like #19680 (might be caused by #34909)

@VikingMew VikingMew changed the title rust bin do not support static library rust bin do not support static and dynamic library Jun 16, 2018
@stokhos stokhos added the A-linkage Area: linking into static, shared libraries and binaries label Jun 17, 2018
@jonas-schievink
Copy link
Contributor

Closing as a duplicate of #34909

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
Projects
None yet
Development

No branches or pull requests

3 participants