简体   繁体   English

__declspec(dllimport)导致MSVC 2010上的编译器崩溃

[英]__declspec(dllimport) causes compiler crash on MSVC 2010

In a *.cpp file, trying to use a third party lib: 在* .cpp文件中,尝试使用第三方lib:

#define DLL_IMPORT 
#include <thirdParty.h>
// Third party header has code like:
// #ifdef DLL_IMPORT
//    #define DLL_DECL __declspec(dllimport)

// fatal error C1001: An internal error has occurred in the compiler.

Alternative: 选择:

#define NO_DLL
#include <thirdParty.h>
// Third party header has code like:
// #elif defined(NO_DLL)
//    #define DLL_DECL


// Compiles fine, but linker errors as can't find DLL functions

I can reproduce results by remove macros and #define all together and manually editing the third party files to have __declspec(dllimport) or not - so the preprocessor stuff above is just to show what's going on, it's not copy-paste. 我可以通过删除宏和#define在一起并手动编辑第三方文件以具有或不具有__declspec(dllimport)的方式来再现结果-因此,上述预处理器的作用只是为了说明正在发生的事情,而不是复制粘贴。

Has anyone come across anything similar, or can hint at the cause? 有没有人遇到类似的事情,或者可以暗示原因? (which is created using CMake). (使用CMake创建)。 Above is actual example of 2 line *.cpp that crashes so it's narrowed down to something in the #include. 上面是2行* .cpp崩溃的实际示例,因此将其范围缩小到#include中。

The following also work fine: 以下内容也可以正常工作:

  1. Compile the examples provided by the third party (they provide a *.sln) that use dllimport/export so it doesn't appear to be the fault of the library 编译使用dllimport / export的第三方提供的示例(它们提供一个* .sln),因此这似乎不是库的问题
  2. Compile the third party lib as part of the production project (so dllexport works fine) 将第三方lib编译为生产项目的一部分(因此dllexport可以正常工作)

I've trawled the project settings pages of the two projects to try and spot differences, but have come up blank. 我已经拖曳了两个项目的项目设置页面,以尝试发现差异,但是空白。 Of course, it's possible I'm missing something as those settings pages are not the easiest to navigate. 当然,我可能会遗漏一些东西,因为这些设置页面并不是最容易浏览的页面。 I'll get access to VS2008 in a day or so, so can compare with that. 我将在一天左右的时间内访问VS2008,因此可以与之进行比较。 The third party library is MySql++. 第三方库是MySql ++。

A compiler crash is definitely a bug in the compiler, so you're best off submitting an error report to the Microsoft Visual C++ team. 编译器崩溃绝对是编译器中的错误,因此,最好将错误报告提交给Microsoft Visual C ++团队。

As for the error 至于错误

#define DLL_DECL __declspec(dllimport)

is the wrong way to go about things. 是处理事情的错误方法。 There should be some project setting you need to set, a pre-processing directive you can define instead if DLL_DECL , or simply including a different file. 应该设置一些项目设置,或者可以定义一个预处理指令,而不是DLL_DECL ,或者只是包含一个不同的文件。

原来是因为为尝试使用DLL的项目打开了预编译头。

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

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