wrap a c++ library in c? (don't “extern c”)

后端 未结 5 1563
走了就别回头了
走了就别回头了 2021-01-12 18:29

is it possible to wrap a c++ library into c?

how could i do this?

are there any existing tools?

(need to get access to a existing c++ library but on

5条回答
  •  误落风尘
    2021-01-12 18:59

    (don't “extern c”)

    extern C only helps you to have a names in dll like you see them.

    You can use
    dumpbin /EXPORTS your.dll
    to see what happens with names with extern C or without it.
    http://msdn.microsoft.com/en-us/library/c1h23y6c(v=vs.71).aspx

    To answer your question... It depends... But it is highly unlikely that you can use it without wrappings. If this C++ library uses just a simple functions and types you can just use it. If this C++ library uses a complex classes structure - probably you will be unable to use it from C without wrapping. It is because the internal of classes may be structured one way or another depending on many conditions (using inference with virtual tables or abstracting. Or in example complex C++ library may have its own object creation mechanisms so you HAVE to use it in the way it is designed or you will get unpredictable behavior).

    So, I think, you have to prepare yourself for doing dome wrappings.

    And here is a good article about wrapping C++ classes. It the article the Author tells about wrapping C++ classes to C# but he uses C at first step.
    http://www.codeproject.com/KB/cs/marshalCPPclass.aspx

提交回复
热议问题