Hi,
I'm trying to build a setup in which I could write .dll libraries that I could
call from excel. Now, I've managed to make it work with C. There I have two
files:
1) excelfunctions.c:
#include <math.h>
double _stdcall square (double *x)
{
return *x * *x;
}
Run
And 2) excelfunctions.def
LIBRARY "excelfunctions"
EXPORTS
squarec = square
looperc = looper
Run
When I compile that with this command, everything works fine and I can call the
functions from excel:
/LD /O2 excelfunctions.c /DEF excelfunctions.def
Run
However with Nim, I can't get it to work. I'm not going to show all the
iterations I have gone through, but here's one. Currently I have one file,
excelnim.nim:
import math
proc square*(x_ptr: pointer): float64 {.stdcall,exportc.} =
var x = cast[ptr float64](x_ptr)[]
return x * x
Run
And I'm trying to compile that with:
c --app:lib --nomain -d:release excelnim.nim
Run
File compiles fine, but Excel tells me that file does not exist (Excel's
general error message when something goes wrong with the dll).
I tried to include the .def file, but couldn't find how to do that from
compiler manual, forums nor numerous discussions I've been reading through. But
I have a lead!
I was comparing how the dll files compare when I open them up with DLL Export
Viewer. I can see the functions nicely when I'm opening the dll file I created
with C compiler (cl), but when I open the file my nim code compiled into, I can
only see NimMain. This is extra confusing since I'm using --nomain in my
options...