Conventions for including external .dll/.so libs to rust crate or program

Hello all,

I'm working on a rust binding to the ngspice library written in C. The (hopeful) plan is to then use it in a circuit simulation program in rust.

up to now, I've just been keeping a copy of the .dll in the repo, but recently it has occurred to me that this may not be a good idea. The readme in opencv-rust for example asks users to install opencv themselves. NgSpice though, as far as I can tell, has no equivalent installation. There are separate downloads for the program (irrelevant to the binding) and the .dll/.so library files.

I've tried looking this up but google keeps misinterpreting my question... maybe I'm wording it incorrectly. :man_shrugging:

So, how should I package a .dll/.so dependency with my project: as a crate, and as an executable binary?

Thanks in advance

If the library is open-source, you can use the cc crate to compile it and link as a static library. This is probably the most portable solution.


To answer specifically this part of the question: you shouldn't ship compiled executables with your code. Rust runs on many different platforms, and it's almost certain you won't be able to produce a (correct) executable for all of them (including all combinations of all possible environments, which arise out of libc incompatibilities, for example).

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.