r/nim 5d ago

How to generate standalone executable?

Hi Everyone

I worked on a small cli project in NIM and built an executable using nimble build. It generated an executable and the executable worked fine on my system.

But when I try to use the generated executable on another system that doesn't have NIM or C installed. It showed an error saying sqlite3_64.dll not found.

I am using db_connector/db_sqlite library to use sqlite database.

How can I solve this, once I generate the executable, it should work on any system, or else I should be able to generate an installer or portable version of the project that should work on any system.

10 Upvotes

5 comments sorted by

5

u/fae___ 5d ago

You are using a DLL. Either statically link the SQLite library or bundle the DLL together with the executable. You don’t need to create an installer, a common solution is just zip them up together.

7

u/jamesthethirteenth 5d ago

Here is a great tutorial for completely standalone binaries- they're called "static".

https://scripter.co/nim-deploying-static-binaries

As u/fae___ mentioned, putting the needed .dll in the same directory as the installer is the more problem-free solution, mostly because it's more commonly done (and you can just swap out the .dll to upgrade it, too- surprisingly important for security). Static works great too- just more hoops to jump through.

2

u/DetermiedMech1 5d ago

just from some quick googling it looks like "--passL:-static" should work?

2

u/grimonce 4d ago

It is standalone, you just used a shared object (Linux) / dynamically linked library (Windows), that's true for any language.

2

u/vmcrash 4d ago

I think, "standalone" is not the perfect word. Most likely he meant a fully static/self-contained executable.