I tried using the shared library created from the modified test8 example, except I only called the functions from a C routine. That is, I didn't use Cython/Python. It looks like I'm getting the same problem here as when I tried using the shared library in Python:
$ ./gambit_tester setup done Gambit-C : (+ 1 2) 3 Gambit-C result : 3
There should also be a "cleanup done" printed out after the call to ___cleanup (), but it doesn't seem to finish that routine.
The code is attached. Do:
$ make tester $ ./gambit_tester
Thanks again.
-Dave
******************************************
Here's the code written out also:
----------------------------------------------------------------------
Use server.scm and server.h from gambit/tests
----------------------------------------------------------------------
/* File: "client.c", Time-stamp: <2007-09-12 00:07:21 feeley> */
#include <stdio.h> #include <stdlib.h> #define ___VERSION 406000 #include "gambit.h" #include "server.h" #define SCHEME_LIBRARY_LINKER ____20_server__
___BEGIN_C_LINKAGE extern ___mod_or_lnk SCHEME_LIBRARY_LINKER (___global_state_struct*); ___END_C_LINKAGE
void gambit_setup( void ) { ___setup_params_struct setup_params; ___setup_params_reset (&setup_params); setup_params.version = ___VERSION; setup_params.linker = SCHEME_LIBRARY_LINKER; ___setup (&setup_params); }
char * gambit_eval( char *in_str ) { char *temp;
temp = eval_string (in_str); if (temp != 0){ printf ("%s\n", temp); } else { printf ("Error: temp == 0\n"); } ___release_string (temp); fflush ( stdout ); return temp; }
void gambit_cleanup ( void ) { fflush (stdout); ___cleanup (); }
----------------------------------------------------------------------
/* gambit_tester.c */
#include "client.h"
int main() {
char *temp;
gambit_setup(); printf("setup done\n");
printf ("Gambit-C : (+ 1 2)\n"); temp = gambit_eval("(+ 1 2)"); printf("Gambit-C result : %s\n", temp); ___release_string (temp);
fflush(stdout); gambit_cleanup(); printf("cleanup done\n"); fflush(stdout);
return 0; }
----------------------------------------------------------------------
C_COMPILER = /usr/bin/gcc-4.2 GAMBIT_GSC = gsc GAMBIT_INC_DIR = /usr/local/Gambit-C/include/ INC_DIR = . GAMBIT_LIB_DIR = /usr/local/Gambit-C/lib/ PYTHON = python PYTHON_INC = /opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 PYTHON_LIB1 = /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib PYTHON_LIB2 = /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config
all: extension standalone gsc tester
gsc: $(GAMBIT_GSC) -link server.scm $(C_COMPILER) -I$(GAMBIT_INC_DIR) -I$(INC_DIR) -Wno-unused -O1 -fno-math-errno -fschedule-insns2 -fno-trapping-math -fno-strict-aliasing -fwrapv -fomit-frame-pointer -fPIC -fno-common -mieee-fp -c -o client.o client.c $(C_COMPILER) -I$(GAMBIT_INC_DIR) -I$(INC_DIR) -Wno-unused -O1 -fno-math-errno -fschedule-insns2 -fno-trapping-math -fno-strict-aliasing -fwrapv -fomit-frame-pointer -fPIC -fno-common -mieee-fp -c -o server.o server.c -D___LIBRARY $(C_COMPILER) -I$(GAMBIT_INC_DIR) -I$(INC_DIR) -Wno-unused -O1 -fno-math-errno -fschedule-insns2 -fno-trapping-math -fno-strict-aliasing -fwrapv -fomit-frame-pointer -fPIC -fno-common -mieee-fp -c -o server_.o server_.c -D___LIBRARY $(C_COMPILER) -shared -I$(GAMBIT_INC_DIR) -I$(INC_DIR) -L$(GAMBIT_LIB_DIR) -lgambc -Wno-unused -O1 -fno-math-errno -fschedule-insns2 -fno-trapping-math -fno-strict-aliasing -fwrapv -fomit-frame-pointer -fno-common -mieee-fp -o libclient.so client.o server.o server_.o tester: gsc $(C_COMPILER) gambit_tester.c -L. -lclient -I/usr/local/Gambit-C/include/ -o gambit_tester
extension: gsc # ======= Cython extension: $(PYTHON) server_setup.py build_ext --inplace standalone: gsc # ======= Cython standalone: $(PYTHON) /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Cython-0.14-py2.7-macosx-10.6-x86_64.egg/cython.py --embed server_setup.pyx $(C_COMPILER) -c server_setup.c -I$(PYTHON_INC) -I$(GAMBIT_INC_DIR) -I$(INC_DIR) $(C_COMPILER) -o server_setup server_setup.o client.o server.o server_.o -L$(GAMBIT_LIB_DIR) -lgambc -L$(PYTHON_LIB1) -L$(PYTHON_LIB2) -lpython2.7 -ldl -framework CoreFoundation
clean: rm -rf gambit.so libclient.so *.o server.c server_.c server_setup.c server_setup.o server_setup build/ gambit_tester
----------------------------------------------------------------------