LLVM Shared DLL not supported reason

Upon reading http://llvm.org/docs/GettingStarted.html it says I can build shared libs, but when going to the CMake doc (http://llvm.org/docs/CMake.html) it says Shared libraries are not supported on Windows and not recommended for other OSes.

Is there a reason why? At least for on Windows.

Windows DLLs generally require that you know what you want to export from them. LLVM has no export annotations or export lists, so we don’t support building DLLs. If you are using mingw, then ld supports the --export-all-symbols flag which might work, but I don’t think it’s well tested.

FWIW, I’ve got a powershell script that builds an exports.def file for recognizable C functions.

You could adapt it to Python and make it part of the official build if the LLVM community thinks it will be beneficial to have libLLVM.dll

The script is located here:

https://github.com/mjsabby/LLVMSharp/blob/master/GenLLVMDLL.ps1

Sure, if you just want the C API, it’s doable with dumpbin or mingw nm. We have a Unix implementation of that in llvm/tools/llvm-shlib/CMakeLists.txt, and we could definitely take a patch for a dumpbin-powered implementation for Windows.

Still, this isn’t the same as having the full C++ API available like we do on other platforms.

As far as I understand, the issue is to "not exporting every function"
(and also potentially exporting C++ functions, which is a lot harder,
because it may require "expanding" templates and name-mangiling). To
actually support those features, it's necessary to have support from
the compiler to say "I want to export this function, I don't want to
export this function".

For simple cases, then exporting everything may be fine. But for
complex software projects, it's typically a bad idea to "export
everything".

Independently of the technical details, etc., I personally wish there was an
official way to have an LLVM DLL. I need it for my project and the way I
currently do it is that I import/export every single class/function that I
need. This is really not ideal since I need to 'patch' LLVM every time a new
release is out. Also, if I need to use an extra class/function, then I need
to rebuild LLVM, etc. So, yes, I would for one certainly welcome an official
way to get an LLVM DLL...

Alan

From: llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu]
On Behalf Of mats petersson
Sent: 01 April 2015 19:31
To: Mukul Sabharwal
Cc: LLVM Developers Mailing List
Subject: Re: [LLVMdev] LLVM Shared DLL not supported reason

As far as I understand, the issue is to "not exporting every function"
(and also potentially exporting C++ functions, which is a lot harder,

because it

may require "expanding" templates and name-mangiling). To actually support
those features, it's necessary to have support from the compiler to say "I

want

Personally, I would also like an LLVM DSO and a Clang DSO that uses
explicit export annotations in the source code.

It's been proposed before, and objections were raised. It might be worth
another try, though.