Call c++ functions using ccall

I have a library in c++, from which I want to call some function. I have tried CxxWrap, which kind of work and seems not stable and I sometimes got segmentation faults.

I tried to call the function using ccall((:myFunc, "....../libmyLib"), .....), but got errors like

ERROR: could not load symbol "myFunc":
....../libmyLib.so: undefined symbol: myFunc

I’ve checked the library with nm -gDC, and the symbol is indeed there.
Does anyone have ideas about this issue? Thanks.

Did you define the function in an extern “C” block?

No…and I just realized that the c symbols are quite different from c++'s symbols. If I use :_Z2myFuncPdm it works.

How can I use extern “C” to get a sensible symbol?

IIRC this should be sufficient:

extern "C" {
    void myFunc() {
        // impl...
    }
}

That works. Thank you!

No worries, I’m happy to hear it solved your issue!