Project structure

Hello @all,

i'm new here and Rust is for me total new. I want to understand an programming with Rust.
Yeah and my first border is the project structure self.
That works for so far. :smiley:

I have two files:
1.) src/
2.) src/

I need src/ as exe and src/ as dll. Both files are in the same project. I have read this tutorial but nothing happens.

What i want is basicly an executeable file and dll file from one project. The dll file is used by the executeable file.

Has anybody a tutorial for me how can i solve this?

Best thanks.

This tutorial gives wrong advice. You should never have mod lib in a Cargo project. It duplicates code and reuses in a way that is not expected by Cargo.

When you have both src/ and src/, Cargo will use to build a Rust library, and then statically link that library into the binary built from src/ The binary will not depend on a DLL. Even if you build DLL at the same time, it will not be used by the binary from the same crate.

Are you sure you want to use a DLL here? It takes much more effort, as you can't use Rust functions on the DLL boundary. You will need to build a stable C API for it. It's a lot of work, and Cargo doesn't support automatically linking with such DLL. That will need making three crates (cdylib crate, sys crate, and the binary crate), a manual build step, and a build script.


Thank for your response and the helpful link about sys crate.

Dont bully me when i say i have Windows as Operationsystem and want to programming with Rust. :smiley:

For me is a testing thing to understand how Rust is working now. I know C# and i have spent lot of time in this language.
You have in C# the possibility to create many Projects in one solution and when the project is a library then they will compile as DLL and all other Projects as executable file.

The only one what i need to understand, how can i work with libraries and what is the best practices.

Best thanks.

In Rust, your libraries are typically compiled into the executable rather than as a DLL.


I understand it now