Name mangling of c++ classes and its member functions?

后端 未结 4 1101
失恋的感觉
失恋的感觉 2021-01-21 01:15

Is there no way I could avoid name mangling of C++ classes and its member functions when exposed from a c++ dll.

Can\'t I use a def file mechanism in this regard ?

4条回答
  •  不知归路
    2021-01-21 01:54

    I think the best way to do this is to provide C wrappers around the C++ library. This was quite popular 10 or more years back when I was programming in C++ but I don't know if it is done any more.

    Basically, for every class C, for every constructor ctor to be exposed to create an extern "C" CPtr cCtor(....) method that returns an opaque pointer CPtr and for every function func to be exposed you create extern "C" cFunc(CPtr,....)

    Another approach is to create a CStruct that has member variables of function pointer types, implement them to call the class methods and let the client do all the hard work.

提交回复
热议问题