[gambit-list] Compiling Gambit-C to dll and loading into .NET
longster at gmail.com
Tue Feb 13 01:18:34 EST 2007
I'm attempting to write a .NET stub for a Scheme program. I want to compile
the gambit scheme code down to C and then compile it into a Windows DLL.
Then I can load this DLL into .NET and write an interface for it.
I've accomplished all of this (with a simple hello world program), but the
.NET app always crashes. The first time I tried it, I used cygwin and
compiled this scheme code:
* (c-define (helloworld) () void "helloworld" ""
* (display "Hello"))
with gsc like this:
* gsc -link func.scm
and then compiled the corresponding c files with gcc like so:
* gcc -Iinclude -shared -D___DYNAMIC func*.c -o func.dll -lgambc -lwsock32
which compiled fine. That should produce a Windows DLL, right? I'm a
little skeptical at that part because I've never used gcc to produce a
windows dll before. But read on before you think that's the problem.
As the final step I created the .NET interface with the following few lines:
* public static extern void helloworld();
And this compiled, but .NET threw an access violation at me when the
function ran. Actually, I fixed some of the gcc flags and got it instead to
throw a NullReference exception when the function returned. Since I was
skeptical about gcc, I tried compiling a hand-rolled ansi c file that
contained the equivalent helloworld function with basically the same gcc
command as above, ran the .NET program and the function ran fine (printed
"Hello World" to the console). It shouldn't be anything with the calling
convention or anything either since it looks like the c file produced by
scheme declares the helloworld function as __cdecl. I know that the
Gambit-C code includes a bunch of other stuff though (note how I had to link
the winsock libraries), so it must be somewhere in there that I'm not
compiling it right or something.
I found the Visual Studio solution files in the gambit directory and tried
compiling gambit to a windows shared lib to see if that would help. I
recompiled the Gambit-C code with visual studio and linked gambit in to a
complete dll, ran the .NET app again, and now it's giving me an exception
saying it can't find an entry point in the dll for the helloworld function.
There's got to be something I'm missing, has anyone else gotten this to
work? Or does anyone see anything wrong with how I'm compiling the dll (the
loading part is relatively simple and I doubt the problem is in there)?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Gambit-list