Problem referencing C++ /clr project from C#
开发者_Python百科I have compiled a native C++ project using the /CLR switch ("gloox", an XMPP library). The build succeeded and I'm able to reference it from a C# project (ie it shows up in the References folder). The C++ project exposes some classes under the namespace 'gloox'.
I can also see the gloox {} namespace in the object browser, along with all the exported classes.
The problem is that from the C# project I can't 'see' the gloox namespace (ie 'using gloox' does not compile).
Thanks
Does the C++ project expose any managed types (ref class
or value class
or enum class
)? The /CLR
option doesn't magically make types available to managed code, you need the managed metadata which is only available for managed types, and the types need to be public to be used from other assemblies.
(To be totally accurate, the C++/CLI compiler sometimes creates metadata for native classes, especially in /clr:pure
mode, but marks these as internal so you can't use them from other languages which don't understand the native C++ rules.)
精彩评论