LLVM 3.6: problems building on Windows using MSVC 2013

Ok, I have just found the cause of the error messages I am getting, and it now makes sense to me why the ‘normal’ build works fine on Windows, Linux and OS X, and why my personal build works on Linux and OS X, but not on Windows. However, I still don’t understand why I am getting the error messages I am getting.

Anyway, it has to do with wanting to export some classes and function, including clang::driver::Compilation. Now, since the export/import of classes/function is not supported by the LLVM+Clang project (incidentally, I really wish it was!), I had to modify the definition of the classes and functions that I need in order to have something like:

class LLVM_EXPORT Compilation { … };

rather than

class Compilation { … };

with LLVM_EXPORT being defined as:

#ifdef _WIN32

#ifdef BUILD_LLVM

#define LLVM_EXPORT __declspec(dllexport)

#else

#define LLVM_EXPORT __declspec(dllimport)

#endif

#else

#define LLVM_EXPORT

#endif

Now, as I mentioned before, that approach works fine up to LLVM+Clang 3.5.1, but it fails with LLVM+Clang 3.6. Not for all the classes/functions that I need to export/import though, only some of them (in Clang, it would seem).

To convince myself, I set up a very simple CMake+Ninja project to build tools/clang/lib/Driver/Compilation.cpp (and nothing else since it’s just for checking) and it builds fine if I have:

class Compilation { … };

but not if I have:

class declspec(dllexport) Compilation { … };

So… my question is: why?! More importantly: what do I need to do to be able to export/import a class such as clang::driver::Compilation?

Cheers, Alan.

It looks like MSVC is trying to synthesize and export the copy
assignment operator and copy constructur. This is interesting, as I
thought it wouldn't do that if the class turns out not to be
non-copyable.

Does adding the following to the class (and similarly for others that
are failing) work?

  Compilation& operator=(Compilation&) = delete;
  Compilation(Compilation&) = delete

- Hans

> So… my question is: why?! More importantly: what do I need to do to be
> able to export/import a class such as clang::driver::Compilation?

It looks like MSVC is trying to synthesize and export the copy assignment
operator and copy constructur. This is interesting, as I thought it wouldn't do
that if the class turns out not to be non-copyable.

Does adding the following to the class (and similarly for others that are
failing) work?

  Compilation& operator=(Compilation&) = delete;
  Compilation(Compilation&) = delete

Good timing. This is the conclusion and solution to which I came too. I have tried it on my test case and it is working fine. I am now going to try it on my project and see how it goes, but at least that seems promising.

Alan

To be certain, are you using MSVC 2013 Update 4?

No, I am currently using MSVC 2013 Update 3. Why? Is there something I should (have) know(n)?

Alan

Update 4 is the minimum required version. I don’t know the exact details of what was fixed between Update 3 and Update 4, but currently if you have anything less than Update 4 our CMake warns about miscompiles and other things.

Ok, thanks for the clarification. I don’t remember seeing any warnings when building LLVM+Clang the ‘normal’ way, but I have nonetheless upgraded to MSVC 2013 Update 4, just to be on the ‘safe side’.

Alan