[Ecls-list] Problems with updating an external global variable

Dietrich Bollmann dietrich at formgames.org
Sat Jul 13 15:31:27 UTC 2013


I compiled my ECL lisp functions with asdf:make-build into a library.

Some functions depend on the value of a global variable which has to be set
in the code using the library.

But when changing the value of the global variable in the code using the
library, the library functions still use the old value...

What can I do?


Here a simplified example using a global integer variable:

The global variable is declared in a header file

--- context.h ---
extern int global_int;

and defined in

--- context.cpp ---
int global_int = 123;

It is used in the following lisp function (test) defined in the library:

(ffi:clines "#include \"context.h\"")
(defun test () (ffi:c-inline () () :void "myprint(global_int);"))

When printing the value from the main program, which includes the header
file context.h as well, changing the value to 456 and printing again works
as expected:

#include "context.h"
global_int = 456;

results in the following being printed:


But when evaluating (test) before and after the value is changed, in both
cases the original value is printed:


What can I do to make the lisp function defined in the library use the new
updated value?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/ecl-devel/attachments/20130714/422dfd62/attachment.html>

More information about the ecl-devel mailing list