Making your own shared libraries
- Posted by Robert Craig <rds at ATTCANADA.NET> Jul 18, 1999
- 471 views
Here's an example of how you can write your own C routines and add them to your Linux Euphoria program. Making a shared library with gcc isn't well documented, but is actually very simple. 1. Create a C source file, say, mylib.c and define one or more C functions : int sum(int x) { int i, sum; sum = 0; for (i = 1; i <= x; i++) sum += i; return sum; } 2. Create a Euphoria program, mylib.exu: include dll.e atom mylib integer sum mylib = open_dll("./mylib.so") if mylib = NULL then puts(2, "Couldn't open mylib.so\n") abort(1) end if sum = define_c_func(mylib, "sum", {C_INT}, C_INT) ? c_func(sum, {10}) -- calls your C routine 3. Make a shared library from your C source file: gcc -shared mylib.c -o mylib.so 4. Run your Euphoria program: exu mylib The output is: 55 - the sum of the integers from 1 to 10. Regards, Rob Craig Rapid Deployment Software http://members.aol.com/FilesEu/