Hi guys! How to build a 32 bit dll in Nim? I'm on 64 bit Windows 10 pro. My Nim is installed via Scoop. It is a 64 bit Nim
Let's take this as proc:
proc multiply(num1, num2: int): int {.stdcall,exportc,dynlib.} = num1 * num2
The dll will be then called from a 32 bit software as plugin (se below)
On reddit they adviced someone to have a 32 mingw compiler.
Ok, I got it:
C:Users<me>DesktopNIM32mingw32bin
I even got a an isolated Nim 32 folder like this:
C:Users<me>DesktopNIM32nim-1.4.2_x32nim-1.4.2binnim.exe
This is my batch file content for compiling:
C:Users<me>DesktopNIM32nim-1.4.2_x32nim-1.4.2binnim.exe c --gcc.path=C:Users<me>DesktopNIM32mingw32bin --app:lib --cpu:i386 --passc: -m32 --passL: -m32 -d:release --no_main mylibrary.nim
It looks like it produces a 32 bit dll.
No error during the compilation. But the resulting dll is not loadable from my c program like this:
#include <stdio.h> #include <windef.h> #include <winbase.h> #include <windows.h>
int main()
{
HINSTANCE testlibrary = LoadLibrary("mylibrary.dll");
if (testlibrary)
{
printf("Ok for the moment...n");
}
return 0;
}
This is c main is compiled this way: gcc -m32 main.c
Can you help me?
nope, are you on phone?
copy this three ```nim [your code] ```
It looks like it produces a 32 bit dll. I can check it with notepad!
Use "CFF Explorer" or similar tools.
Thank you very much for the hint!
libgcc_s_dw2-1.dll was missing among the dependencies. I spotted iit with cff explorer.
Now everything works!!
Ps.: Of course no need for a separate NIM 32 installation. Scoop global NIM suffices.
I still need a separate mingw32 folder.
Thank you
I've faced that issue aswell. Either use a pragma or pass it manually:
{.passL: "-static-libgcc -static-libstdc++".}
Interesting!
Sorry, ignorance. By adding this pragma (where exactly?), there is no need for libgcc_s_dw2-1.dll ?