简体   繁体   English

从C#引用C ++ / clr项目时出现问题

[英]Problem referencing C++ /clr project from C#

I have compiled a native C++ project using the /CLR switch ("gloox", an XMPP library). 我已经使用/ CLR开关(“ gloox”,一个XMPP库)编译了一个本机C ++项目。 The build succeeded and I'm able to reference it from a C# project (ie it shows up in the References folder). 构建成功,我可以从C#项目中引用它(即,它显示在“引用”文件夹中)。 The C++ project exposes some classes under the namespace 'gloox'. C ++项目在名称空间“ gloox”下公开了一些类。

I can also see the gloox {} namespace in the object browser, along with all the exported classes. 我还可以在对象浏览器中看到gloox {}名称空间,以及所有导出的类。

The problem is that from the C# project I can't 'see' the gloox namespace (ie 'using gloox' does not compile). 问题是从C#项目中,我无法“看到” gloox命名空间(即“使用gloox”无法编译)。

Thanks 谢谢

Does the C++ project expose any managed types ( ref class or value class or enum class )? C ++项目是否公开任何托管类型( ref classvalue classenum 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. /CLR选项不会神奇地使类型对托管代码可用,您需要仅对托管类型可用的托管元数据,并且这些类型必须是公共的,才能从其他程序集中使用。

(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.) (确切地说,C ++ / CLI编译器有时会为本机类创建元数据,尤其是在/clr:pure模式下,但是将其标记为内部元数据,因此您不能从不了解本机C ++规则的其他语言中使用它们。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM