如何将lib文件添加到C ++库,然后在c#项目中使用该库 [英] How to add lib files to C++ library and then use this library in c# project

查看:280
本文介绍了如何将lib文件添加到C ++库,然后在c#项目中使用该库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以就是这样。



我有一个c库。我需要在C#项目中使用几个函数



所以我想我需要创建一个C ++库来用作导出这些函数的包装器。然后在我的C#项目中添加此库作为参考。



问题是当我尝试使用来自另一台PC的库时,lib文件的路径无效更多,所以它给了我一个错误。



所以我如何移动C ++库,同时引用的lib文件总能正常工作



是否类似于C ++中的动态引用lib文件?

So here is the thing.

I have a c library. I need to use several functions from there in a C# project

So I was thinking I need to create a C++ library to be used as wrapper to export these functions. Then add this library as a reference in my C# project.

The problem is that when I try to use the library from another pc the path for lib files are not valid any more so it is giving me an error.

So how I can move C++ library and at the same time the lib files referenced there could always work

Is it something like dynamic referencing lib file in C++ ?

推荐答案

您不需要为C函数创建C ++包装器:您可以直接引用它们与通过DLL文件中的DllImport进行C ++函数的方式相同。由于Platform Invoke只需要在DLL文件中将函数声明为C风格,因此更少考虑一下! :笑:



见这里: http: //msdn.microsoft.com/en-us/library/ms235282.aspx [ ^ ]
You don't need to create a C++ wrapper for C functions: you can reference they directly in the same way you would C++ functions via DllImport from a DLL file. Since Platform Invoke requires only that the functions are declared C-style in the DLL file, it's even one less thing to think about! :laugh:

See here: http://msdn.microsoft.com/en-us/library/ms235282.aspx[^]


第一步是生成C库。它必须以裸格式导出名称。生成的dll应包含在C#输出目录中。请保留所有必需的dll。



我写过文章呼叫所有站点处理很多这样的事情。 (知道这些问题)
The first step is to produce a C library. It must export the names in "naked format". The resulting dll should get included in the C# output directory. Be shure to include all needed dlls.

I have written the article Calling All Stations which handles a lot of this stuff. (in knowning these problems)


这篇关于如何将lib文件添加到C ++库,然后在c#项目中使用该库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆