Preventing name mangling in C++ applications?


My applications are written in C++ and while everything works as expected I’ve noticed some problems that are arising due to potential name mangling. Specifically, when I try to use the config tree API (le_cfg.api), I get build errors

error: ‘le_cfg_CreateReadTxn’ was not declared in this scope

I have the api in the requires section of my cdef


It works when I declare the function le_cfg_CreateReadTxn in an extern “C” block leading me to believe that it’s due to name mangling. Is this by design or am I doing something wrong?

Well, to my understanding the legato project is written in C and therefore you will have to add the legato function in a extern C block to be able to access them from C++ as the linker will otherwise try to find a C++ function with that given interface.
So to answer your question, I think it is by design (or at least a consequence of the design choice to write the legato framework in C).

I believe legato headers already have extern C in them, so there is no need to do it again. My problem was that I was missing “interfaces.h” and I ended up making a mountain of a mole hill :slight_smile:.