[LLVMdev] LLVM 3.6: problems building on Windows using MSVC 2013

Hans Wennborg hans at chromium.org
Tue Mar 10 09:05:25 PDT 2015


On Tue, Mar 10, 2015 at 5:20 AM, Alan Garny <agarny at hellix.com> wrote:
> 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?

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




More information about the llvm-dev mailing list