0

In a *.cpp file, trying to use a third party 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.

Has anyone come across anything similar, or can hint at the cause? (which is created using CMake). Above is actual example of 2 line *.cpp that crashes so it's narrowed down to something in the #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
  2. Compile the third party lib as part of the production project (so dllexport works fine)

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. The third party library is MySql++.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
Zero
  • 11,593
  • 9
  • 52
  • 70

2 Answers2

1

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.

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.

Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
  • I'm constrained by the third party, but you're right - it has a macro which I set which causes #define DLL_DECL to be the first line of the included file. I pulled it out in the example for clarity - in reality there's a swathe of settings, but I can manually type the __declspec part in the third party headers to reproduce result so I'm pretty confident that's the root problem. – Zero Sep 13 '12 at 09:29
  • @Zero that only makes it confusing. That's the macro you should be using, `DLL_DECL` seems to be internal to the library and you shouldn't alter it. – Luchian Grigore Sep 13 '12 at 09:32
  • Fair point - I've edited for clarity, hopefully it's better now. – Zero Sep 13 '12 at 09:39
  • @Zero Do you have a `lib` file to link against? – Luchian Grigore Sep 13 '12 at 09:41
  • MySql++ seems to have another problem where inheriting from std::ostream causes linker errors when you link statically. I'm chasing that issue separately. Thanks for your help. – Zero Sep 13 '12 at 23:04
0

Turns out it was because precompiled headers was turned on for the project trying to use the DLL.

Zero
  • 11,593
  • 9
  • 52
  • 70