C++ / CLI 预编译头:它们如何工作?
我正在尝试编写一个混合模式 DLL,我们将其称为“客户端”,用托管类替换一些非托管类。 在我的个人机器上一切正常,但是当我签入源代码时,我们的构建机器将无法构建项目。 它无法识别我从另一个 DLL(称为“Core”)使用的托管类。
我认为这个问题与预编译头有关。 原因如下:
为了使用“Core”中的类,我在“Client”项目中添加了对“Core”项目的引用。 如果我删除此引用,然后在我的个人计算机上构建该项目,它仍然可以工作。 不过,删除引用后,CLR PCH 不会重新编译。 如果我重新编译 CLR PCH,然后编译该项目,它会失败,并出现与构建计算机上相同的错误:无法识别托管类。
在我看来,您导入的 DLL 中的托管类是在预编译头中定义的。 我无法验证这一点,但这是我最好的猜测。 有谁对这个问题有什么见解吗? 混合 DLL 中的项目引用是否通过将挂钩放入托管 PCH 来解析?
重现步骤
以下内容对我来说毫无意义:
- 获取客户端进行构建。
- 删除从客户端到核心的引用。 编译客户端。 客户端仍在构建。 这是预料之外的。
- 重新编译Client PCH,然后编译Client。 编译客户端失败:“Core”中的类未定义。 这是预期的行为。
- 添加Core引用,编译。 由于同样的原因,编译客户端失败。 这不是预期的情况。
- 重新编译Client PCH,然后编译Client。 客户端编译良好。
我从这个实验中得到的结论是,引用是通过预编译头插入到项目中的,并且这种工作方式被破坏了,至少在我们的构建机器上是这样。
I'm trying to write a mixed-mode DLL, let's call it 'Client', to replace some unmanaged classes with their managed equivalents. Everything works fine on my personal machine, but when I check the source code in, our build machine won't build the project. It doesn't recognize the Managed classes I'm using from another DLL, called 'Core.'
I think the issue has to do with precompiled headers. Here's why:
To use the classes from 'Core', I added a reference to the 'Core' project in the 'Client' Project. If I remove this reference and then build the project on my personal machine, it still works. The CLR PCH doesn't recompile after removing the reference, though. If I recompile the CLR PCH, and then compile the project, it fails with the same errors that I get on the build machine: the managed classes are not recognized.
It seems to me that the managed classes from DLL's you import are defined in the precompiled header. I haven't been able to verify this, but that's the best guess I have. Does anyone have any insight they can shed on this issue? Are project references in Mixed DLL's resolved by putting hooks into the managed PCH?
Steps to Reproduce
The following makes no sense to me:
- Get Client to build.
- Remove the Reference from Client to Core. Compile Client. Client STILL builds. This is not expected.
- Recompile the Client PCH, then compile Client. Compile Client fails: the classes in 'Core' are undefined. This is expected behavior.
- Add Reference to Core, compile. Compile Client fails for the same reason. This is not expected
- Recompile the Client PCH, then compile Client. Client compiles fine.
My conclusion from this experiment is that the References are inserted into the project via precompiled headers, and that something is broken with the way this works, at least on our build machine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
还有另一种方法可以在 C++/CLI 中添加对托管/混合模式 dll 的引用 - 即将#using Core.dll 添加到客户端。 这可能会解决您的构建问题。
There is another way to add references to a managed / mixed mode dll in C++/CLI - it's to add #using Core.dll to Client. This might solve your build problem.
它不能像那样工作,因为您不需要使用预编译头。
PCH 所做的一切就是让您加快构建速度。
它对引用没有做任何特别的事情......
It can't work like that can it, because you don't need to use a precompiled header.
All a PCH does is allow you to speed up the build.
It doesn't do anything special with references.....