[llvm-dev] Disabling inline compilation (Clang with VS2019)

John Emmas via llvm-dev llvm-dev at lists.llvm.org
Mon Sep 27 08:28:08 PDT 2021


Aaaargh!!  I just realised this was a spelling mistake at my end.  
Here's my original example...

On 22/09/2021 13:22, John Emmas wrote:
>
> #if defined (BUILDING_DLL)
>   #define DLL_API __declspec(dllexport)
> #else
>   #define DLL_API __declspec(dllimport)
> #endif
>

But because the library can be built for different platforms, the actual 
code here was slightly more complicated - looking like this:-

     #if defined (COMPILER_MSVC)
       #if defined (BUILDING_DLL)
         #define DLL_API __declspec(dllexport)
       #else
         #define DLL_API __declspec(dllimport)
       #endif
     #else
         #define DLL_API
     #endif

I'd changed the first line to read #if defined (COMPILER_MSVC) || 
defined (COMPILER_CLANG) - except that in the actual VS project file I'd 
then mis-spelled COMPILER_CLANG - so apologies and thanks to everyone 
who's helped here...  I'd spent days looking through header files and 
source files without even thinking to check the VS project itself :-(

Fixing this has made it compile and link with optimizations disabled 
('/Ob0') but I guess I'll need to check what happens once I enable them 
again.  If header-defined functions are routinely treated as inlined, I 
guess the problem might come back again :-(

I suppose this brings up an obvious question...  when building with MSVC 
I could have used the built-in preprocessor directive _MSC_VER rather 
than using my own COMPILER_MSVC - so does Clang have something built-in 
that's always similarly #defined?  Or even better - does anyone know if 
there's some preprocessor directive that's always specified for both 
compilers (i.e. when they're being used with Visual Studio) ?

Thanks again, John


More information about the llvm-dev mailing list