Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't llvm-config on Windows emit the correct parameters for clang++.exe?

I'm no experienced LLVM user, but I'm trying to compile a Linux LLVM project on Windows. The project is GHDL.

Because ready-to-use LLVM installers for Windows don't have llvm-config bundled, I needed to compile LLVM and clange from sources. The project requires LLVM 3.5.

So first, I downloaded llvm-3.5.2 and clang-3.5.2 and used CMake to translate it into Visual Studio 2013 projects. Then I used VS2013 to compile it.

The original makefile calls llvm-config. The resulting string is passed to clang++:

clang++ -c -I`/usr/lib/llvm-3.5/bin/llvm-config --includedir --cflags --cxxflags` -o llvm-cbindings.o src/ortho/llvm/llvm-cbindings.cpp

I'm using PowerShell to call llvm-config and store the result in a variable:

$LLVM_CONFIG_RESULT = & $LLVM_CONFIG --cxxflags

The result is:

-IC:\Tools\LLVM-3.5/include  /DWIN32 /D_WINDOWS /W3     /MP -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -wd4146 -wd4180 -wd4244 -wd4267 -wd4291 -wd4345 -wd4351 -wd4355 -wd4503 -wd4624 -wd4722 -wd4800 -w14062 -we4238 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS

I notice several problems:

  1. Some paths have / instead of \
    -IC:\Tools\LLVM-3.5/include
  2. Some switches and parameters are used with - others with /
    ... -IC:\Tools\LLVM-3.5/include /DWIN32 /D_WINDOWS ...
  3. Some parameters are delimited by more then one space sign
    ... /W3 /MP ...
  4. clang++.exe prints errors on unknown arguments:

    clang++.exe: error: unknown argument: '-wd4146'
    clang++.exe: error: unknown argument: '-wd4180'
    clang++.exe: error: unknown argument: '-wd4244'
    clang++.exe: error: unknown argument: '-wd4267'
    clang++.exe: error: unknown argument: '-wd4291'
    clang++.exe: error: unknown argument: '-wd4345'
    clang++.exe: error: unknown argument: '-wd4351'
    clang++.exe: error: unknown argument: '-wd4355'
    clang++.exe: error: unknown argument: '-wd4503'
    clang++.exe: error: unknown argument: '-wd4624'
    clang++.exe: error: unknown argument: '-wd4722'
    clang++.exe: error: unknown argument: '-wd4800'
    clang++.exe: error: unknown argument: '-w14062'
    clang++.exe: error: unknown argument: '-we4238'

The result is now included into the clang++.exe call, which causes errors.

Command: 'C:\Tools\LLVM-3.5\bin\clang++.exe -c -c -v -IC:\Tools\LLVM-3.5/include  /DWIN32 /D_WINDOWS /W3     /MP -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -wd4146 -wd4180 -wd4244 -wd4267 -wd4291 -wd4345 -wd4351 -wd4355 -wd4503 -wd4624 -wd4722 -wd4800 -w14062 -we4238 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -o llvm-cbindings.o ../../src\ortho\llvm\llvm-bindings.cpp -o llvm-cbindings.o ../../src\ortho\llvm\llvm-cbindings.cpp'  
clang++.exe: error: unknown argument: '-wd4146'  
clang++.exe: error: unknown argument: '-wd4180'  
clang++.exe: error: unknown argument: '-wd4244'  
clang++.exe: error: unknown argument: '-wd4267'  
clang++.exe: error: unknown argument: '-wd4291'  
clang++.exe: error: unknown argument: '-wd4345'  
clang++.exe: error: unknown argument: '-wd4351'  
clang++.exe: error: unknown argument: '-wd4355'  
clang++.exe: error: unknown argument: '-wd4503'  
clang++.exe: error: unknown argument: '-wd4624'  
clang++.exe: error: unknown argument: '-wd4722'  
clang++.exe: error: unknown argument: '-wd4800'  
clang++.exe: error: unknown argument: '-w14062'  
clang++.exe: error: unknown argument: '-we4238'  
clang version 3.5.2 (tags/RELEASE_352/final)  
Target: i686-pc-windows-msvc  
Thread model: posix  
clang++.exe: error: no such file or directory: '/DWIN32'  
clang++.exe: error: no such file or directory: '/D_WINDOWS'  
clang++.exe: error: no such file or directory: '/W3'  
clang++.exe: error: no such file or directory: '/MP'  

So here are my questions:

  • Why does llvm-config emit false results on Windows?
  • How can I fix it?
  • What are these -wd*** switches for?
like image 823
Paebbels Avatar asked Mar 13 '23 16:03

Paebbels


1 Answers

Why does llvm-config emit false results on Windows?

How can I fix it?

It does not. llvm-config gives you the right arguments but you use the wrong frontend for Windows. clang++ is build for platforms that originally have a GNU compiler tool-chain (g++ etc.). The Windows frontend (clang-cl) is a replacement for the Visual Studio tool-chain and accepts the values provided by llvm-config.

From your usecase calling clang++ results in:

PS C:\Users\XXX> clang++ -wd4146
clang++.exe: error: unknown argument: '-wd4146'
clang++.exe: error: no input files

while calling clang-cl:

PS C:\Users\XXX> clang-cl -wd4146
clang-cl.exe: error: no input files

works as intended. This is because the GNU and the Visual Studio tool-chains have different command line flags for the frontend. This leads to your last question:

What are these -wd*** switches for?

With -wd*** switches you disable specific compiler warnings for example 4146 is documented here:

C4146: unary minus operator applied to unsigned type, result still unsigned
like image 117
Michael Haidl Avatar answered Mar 16 '23 04:03

Michael Haidl