Stateful modules and extern(C)

Arredondo at
Thu May 24 22:58:09 UTC 2018

I want to call some of my D code from Python. I'm annotating the 
pertinent functions with extern(C) export, as in

module foo;
extern(C) export int initialize() {
     return 42;

I compile with:

dmd -fPIC -shared ./foo.d

 From the Python end, I can load the library using ctypes and the 
call works fine. The problem is, as soon as I have some state in 
my D module, as in:

module foo;

int call_count;

extern(C) export int initialize() {
     return 42;

the call to initialize from python gives:

AttributeError: ./ undefined symbol: initialize

Can you share some tips/examples of non-trivial/stateful D 
modules that are successfully export(C)ed and maybe consumed with 
ctypes? Are there any specific attributes that I need to annotate 
my module globals with?

Thank you!

More information about the Digitalmars-d-learn mailing list