Skip to content

rust bin do not support static and dynamic library #51600

Closed
@VikingMew

Description

@VikingMew

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)

Activity

jonas-schievink

jonas-schievink commented on Jun 16, 2018

@jonas-schievink
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

VikingMew commented on Jun 16, 2018

@VikingMew
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

jonas-schievink commented on Jun 16, 2018

@jonas-schievink
Contributor

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

changed the title [-]rust bin do not support static library[/-] [+]rust bin do not support static and dynamic library[/+] on Jun 16, 2018
added
A-linkageArea: linking into static, shared libraries and binaries
on Jun 17, 2018
jonas-schievink

jonas-schievink commented on Feb 9, 2020

@jonas-schievink
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binaries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @VikingMew@jonas-schievink@stokhos

        Issue actions

          rust bin do not support static and dynamic library · Issue #51600 · rust-lang/rust