如何使用 C++ 静态库编译 C# 应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/729562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to compile C# application with C++ static library?
提问by Ivan Prodanov
I turned my C++ Dynamic link library into Static library just to acquire more knowledge. My question is how can I use the .obj file to compile both projects with C# express/MS visual studio?
我把我的 C++ 动态链接库变成了静态库,只是为了获得更多的知识。我的问题是如何使用 .obj 文件通过 C# express/MS Visual Studio 编译两个项目?
采纳答案by Jon Skeet
No, you can't access static libraries directly from C#. You haveto use a DLL.
不,您不能直接从 C# 访问静态库。您必须使用 DLL。
回答by abatishchev
No way to do that.
没办法那样做。
Only call DLL functions in runtime or create a COM object from your library
仅在运行时调用 DLL 函数或从库中创建 COM 对象
回答by Mohammad Tayseer
"Static library" means that the library is going to be merged with your final application. This concept doesn't exist in .net. .net supports DLLs only.
“静态库”意味着该库将与您的最终应用程序合并。这个概念在 .net 中不存在。.net 仅支持 DLL。
回答by Erich Mirabal
The way to "use" a static library in C# is to first create a Managed C++ wrapper that will provide a facade for the rest of the managed world. As everyone else has already commented, C# only supports DLLs for P/Invoke.
在 C# 中“使用”静态库的方法是首先创建一个托管 C++ 包装器,它将为托管世界的其余部分提供外观。正如其他人已经评论过的那样,C# 仅支持 P/Invoke 的 DLL。