简体   繁体   English

静态库周围的托管C ++包装器

[英]Managed C++ wrapper around a static library

I am using Visual Studio, .Net and Windows. 我正在使用Visual Studio,.Net和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' 链接:致命错误LNK1104:无法打开文件'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. 我创建了一个C ++ CLR类库项目。 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. 我以为是这样,但是如果我做错了,那么它将节省我一些时间,使我知道我试图做的事情行不通。

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. 我遇到的一个麻烦是,我的非托管代码仅在VS2008中编译,而我需要放入的托管代码仅在VS2010中编译。 So here's what I did: 所以这就是我所做的:

  1. built my unmanaged code as usual, into a static library using VS2008. 使用VS2008将我的非托管代码像往常一样构建到静态库中。 This produces MyUnmanagedClasses.lib 这将产生MyUnmanagedClasses.lib

  2. In VS 2010, right click/Properties on the (managed) project where I want to use the unmanaged code 在VS 2010中,在要使用非托管代码的(托管)项目上单击鼠标右键/属性

  3. Select Linker/Input 选择链接器/输入

  4. in the first box "Additional Dependencies", add MyUnmanagedClasses.lib 在第一个框“其他依赖项”中,添加MyUnmanagedClasses.lib

  5. Select Linker/General 选择链接器/常规

  6. in the "Additional Library Directories" box, add the directory where MyUnmanagedClasses.lib is located 在“其他库目录”框中,添加MyUnmanagedClasses.lib所在的目录

  7. 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. 只需如上所述链接到库中即可。

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

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