(also posted to comp.lang.lisp)
Hi all:
I have a lisp image that contains the following functions:
(defun frgo (a) (format *debug-io* "~%~A~&" a) (values))
(cffi:defcallback frgo_helper :void ((a-cstr :string)) (frgo (cffi:foreign-string-to-lisp a-cstr)))
In a C dynamic library I have:
* file frgo_c.h:
extern void frgo_helper( char * a );
* file frgo_c.c:
void frgo( char * a ) { frgo_helper( a ); }
Now, the library does not compile - undefined symbol _frgo_helper() !
How do I make functions "known" to C land that are purely defined as callbacks in Lisp land?
I tried to declare the function in C land like this:
extern void frgo_helper( char * a ) __attribute__((weak_import));
No luck, though. My environment is:
Mac OS X Snow Leopard (10.6.8), Apple LLVM compiler 3.0.
An ideas / hints / tipps? Thanks a lot!
Cheers
Frank
On Sat, 2012-09-22 at 21:27 +0200, Frank Goenninger wrote:
(also posted to comp.lang.lisp)
Hi all:
I have a lisp image that contains the following functions:
(defun frgo (a) (format *debug-io* "~%~A~&" a) (values))
(cffi:defcallback frgo_helper :void ((a-cstr :string)) (frgo (cffi:foreign-string-to-lisp a-cstr)))
In a C dynamic library I have:
- file frgo_c.h:
extern void frgo_helper( char * a );
- file frgo_c.c:
void frgo( char * a ) { frgo_helper( a ); }
Now, the library does not compile - undefined symbol _frgo_helper() !
How do I make functions "known" to C land that are purely defined as callbacks in Lisp land?
You can't do that directly. Lisp callbacks must be passed to the C code as function pointers. You could write a C wrapper that calls the callback through a global variable and have the Lisp-side store the address of the callback in that variable.
Am 22.09.2012 um 23:18 schrieb Stelian Ionescu:
On Sat, 2012-09-22 at 21:27 +0200, Frank Goenninger wrote:
How do I make functions "known" to C land that are purely defined as callbacks in Lisp land?
You can't do that directly. Lisp callbacks must be passed to the C code as function pointers. You could write a C wrapper that calls the callback through a global variable and have the Lisp-side store the address of the callback in that variable.
Hmm - thanks! I hoped for a far more elegant solution ... Well, it's C after all ... ;-)
Regards
Frank