托管 C++静态库的包装器
我正在使用 Visual Studio、.Net 和 Windows。
我正在围绕静态库编写一个包装器。我需要帮助解决的问题是错误消息:
链接:致命错误 LNK1104:无法打开文件“Unmanagement.lib”
“Unmanagement”是我的项目中的一个类,但它不是项目的名称。
我创建了一个 C++ CLR 类库项目。在其中我创建了一个托管类和一个非托管类。非托管类调用静态库。托管类使用非托管类。编译器和链接器似乎试图为非托管类创建一个库,但这不是应该发生的事情。
我可以在托管类库项目中拥有非托管类(仅由托管类使用)吗?我认为是这样,但如果我错了,那么这会节省我的时间,让我知道我想做的事情是行不通的。
I am using Visual Studio, .Net and Windows.
I am writing a wrapper around a static library. The problem I need help with is the error message:
LINK : fatal error LNK1104: cannot open file 'Unmanaged.lib'
"Unmanaged" is a class in my project but it is not the project's name.
I created a C++ CLR Class Library project. In it I created a managed class and an unmanaged class. The unmanaged class calls the static library. The managed class uses the unmanaged class. The compiler and linker seem to be trying to create a library for the unmanaged class, but that is not what should happen.
Can I have an unmanaged class (that is used only by the managed class) in a managed class library project? I assume so but if I am wrong then it will save me time to know that what I am trying to do will not work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚开始第一次编写托管代码,并且花了很长时间才弄清楚如何使用我的非托管类库。但我想出了一种方法来做到这一点。是的,您可以在同一个库中拥有托管类和非托管类。在我的例子中,一个复杂的问题是我的非托管代码只能在 VS2008 中编译,而我需要放入的托管代码只能在 VS2010 中编译。所以这就是我所做的:
像往常一样使用 VS2008 将我的非托管代码构建到静态库中。这会生成 MyUnmanagementClasses.lib
在 VS 2010 中,右键单击我要使用非托管代码的(托管)项目上的属性
选择链接器/输入
在第一个框“其他依赖项”中添加MyUnmanagementClasses.lib
选择Linker/General
在“Additional Library Directoryies”框中,添加目录MyUnmanagedClasses.lib 所在的位置
像往常一样使用非托管类会的!
注意:不要将非托管项目本身添加到您的解决方案中——这是我首先尝试的方法,但它不起作用;只需按照我上面所述链接到库即可。
I just started writing managed code for the first time, and had quite a time figuring out how to use my library of unmanaged classes. But I figured out one way to do it. And yes, you can have managed and unmanaged classes in the same library. A complication in my case, is that my unmanaged code only compiles in VS2008, while the managed code I need to put it in, only compiles with VS2010. So here's what I did:
built my unmanaged code as usual, into a static library using VS2008. This produces MyUnmanagedClasses.lib
In VS 2010, right click/Properties on the (managed) project where I want to use the unmanaged code
Select Linker/Input
in the first box "Additional Dependencies", add MyUnmanagedClasses.lib
Select Linker/General
in the "Additional Library Directories" box, add the directory where MyUnmanagedClasses.lib is located
Use your unmanaged classes just as you always would!
Note: do NOT add the unmanaged Projects themselves into your solution--that's what I tried first, and it did not work; just link in the libraries as I stated above.