Re: Wrapping a C library.
- Posted by mattlewis (admin) Jan 16, 2012
- 2129 views
This is something I've been thinking about doing for a while, but to be honest I find C a bit intimidating and have never used any of Euphoria's "wrapping" functions. I'd like to use the Gnuplot plotting program directly from Eu (to create graphs on the fly) and there's a simple C library - http://ndevilla.free.fr/gnuplot/ which should do the job.
To be honest, I'm clueless as to where to start. Do I need to know C to do this stuff? I've been looking at the simple example on calling C functions in the demo folder and it seems easy enough, but do I need to compile the C code into a shared library first? Any advice appreciated.
Yes, you'll need to compile that yourself, although it looks fairly simple. I tried downloading it, and it's a single file. After extracting it, I went into the source directory and did:
gnuplot_i-2.10/src$ gcc -fPIC gnuplot_i.c -shared -o gnuplot_i.soThat built the shared library for me, and should work for you. One note: if you're on a 64-bit system, but using 32-bit euphoria, you'll want to tell gcc to use the -m32 flag:
gnuplot_i-2.10/src$ gcc -m32 -fPIC gnuplot_i.c -shared -o gnuplot_i.so
Then you should be able to wrap the library. Looking at the API, it mostly takes pointers to values (which is what the asterisks mean in C), so make sure that you're allocating and passing pointers. If you have specific questions, please ask!
Matt