Author Topic: To use Clang-cl.exe with Codeblocks on Windows 10 needs a new compiler type  (Read 8091 times)

Offline pabristow

  • Multiple posting newcomer
  • *
  • Posts: 75
I have been trying to use CodeBlocks on Windows 10 to using the latest Clang compiler (8.0) to build Boost libraries especially Boost.Math and Boost.Multiprecision, but conclude after some confusing work that Windows really needs a new compiler type using clang-cl.exe and not clang.exe.  This is because Clang-cl.exe is a variant specifically adapted to work with Windows (and Visual studio) and it responds, confusingly, to (some) MS style configuration command like /EHsc (and not -fexceptions) and /std:c++17 (and not -std=c++17).

https://clang.llvm.org/docs/MSVCCompatibility.html

In turn, this also has implications for Boost's complex multi-platform configuration system.

This means some changes are needed to

 C:\Program Files (x86)\CodeBlocks\share\CodeBlocks\templates\wizard\common_functions.script

and

C:\Program Files (x86)\CodeBlocks\share\CodeBlocks\compilers\options_clang.xml

that at a glance I conclude are not in my skill-set ;)

I hope someone will be able to tackle this for the next release because it allows side-by-side IDE development of code for GCC and Clang, something that Visual Studio still does not permit.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Can you show a command line, how a typical c-lang compilation for windows would look like? i can not find anything in the link you provided...

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
pabristow:
Are you using the llvm compiler to run clang-cl?
Have you tried to run the Visual studio compiler instead?
clang-cl is meant to be a drop in replacement for cl.exe, so it should work just fine when using with the Visual studio compiler in Code::Blocks.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline pabristow

  • Multiple posting newcomer
  • *
  • Posts: 75
I have finally returned to this problem after being distracted on other maintenance and release issues.

I have used clang-cl.exe with some success, but for reasons too complex to discuss here, I would like to use the pure Clang compiler with the latest lld linker in order to confirm that this works using Windows as the base for Codeblocks.

This works for me, until I include the need for exceptions handling by including try'n'catch blocks, but I find, after a distressing amount of debugging, that exceptions are not being handled correctly (and as a result the .o link fed to the linker silently does not produce any .exe file).

A warning that there is trouble ahead was that

after CodeBlocks creating a project and choosing Clang 9.0.0 as compiler it says

 "This wizard doesn't know how to set up exception handling for this compiler".

I think this means I have messed up the global compiler configuration :-(

Sadly (and most regrettably IMO because everyone should be using the latest versions with the least number of bugs), the standard release does not include even moderately new Clang compilers (but a lot that I will never use).

Meanwhile can anyone suggest how to get back to the default Clang provided.

and how to reconfigure for new versions.  I would appear that one just needs to copy and then change the toolset executables to match.  Is this correct?

Do I need to remove and reinstall CodeBlocks?  Or can I refressh just key files?

Thanks

Paul








Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
after CodeBlocks creating a project and choosing Clang 9.0.0 as compiler it says

 "This wizard doesn't know how to set up exception handling for this compiler".
Are you sure this is the exact spelling of the message? I don't see such thing in our whole codebase. :shrug:

Sadly (and most regrettably IMO because everyone should be using the latest versions with the least number of bugs), the standard release does not include even moderately new Clang compilers (but a lot that I will never use).
What do you mean by this? CB doesn't ship clang on windows. We ship mingw to make it easier for some users, but we cannot ship all compilers we support. It is not our goal.


Meanwhile can anyone suggest how to get back to the default Clang provided.

and how to reconfigure for new versions.  I would appear that one just needs to copy and then change the toolset executables to match.  Is this correct?

Yes this is how it works. Changing the base path should get you a working compiler. But I've not tested if the clang xml files are working correctly with the latest clang releases on windows.

Do I need to remove and reinstall CodeBlocks?  Or can I refressh just key files?
No you don't have to... The changes done in the ui are saved in your user folder. If you want to reset your setting you can just delete them (somewhere in AppData/...../CodeBlocks)

Have you tried to compile simple program with exceptions on the command line? Does it work? Do you pass -fexceptions (or whatever the correct spelling for this is, check the clang manual)?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline pabristow

  • Multiple posting newcomer
  • *
  • Posts: 75
Sorry, message was in a box that you can't just copy'n'paste, so I mistyped it  :-(

 the message was from Line 268 in function cppExceptions

        ShowWarning(_T("This wizard doesn't know how to setup exception flags for this compiler.\n"));

I am using mingw-w64

"C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0"

So does this need uncommenting this line for clang  to get it to add -fexceptions ?  ( will check that this is needed)

            // || GetCompilerFactory().CompilerInheritsFrom(compilerID, _T("clang"))

or have I messed up something else?

Probably - as adding -fexceptions to the build options still does not produce an .exe  :(

I'll try deleting my appdata stuff (after saving some files) and report back.

Thanks for help so far.

Paul

PS I was suggesting that supporting the most recent compiler version would be most useful, at least on nightly builds.





Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
So does this need uncommenting this line for clang  to get it to add -fexceptions ?  ( will check that this is needed)

            // || GetCompilerFactory().CompilerInheritsFrom(compilerID, _T("clang"))

or have I messed up something else?
The latest version of this file has this line uncommented, so it seems exceptions for clang are supported.

Probably - as adding -fexceptions to the build options still does not produce an .exe  :(
Does it work on the command line?
Can you post a full rebuild log?
Have you read our FAQ at  http://wiki.codeblocks.org/index.php/FAQ-Compiling_(errors) ?

BTW: The wizard just creates the project file with initial settings. You can later add or remove most of the compiler and linker flags.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline pabristow

  • Multiple posting newcomer
  • *
  • Posts: 75
I shot my myself in the foot by adding --version to try to record the linker version (useful when you are trying to confirm that all the available linkers (clang++, clang-cl, ld, lld and gold all work as expected) :-[

I forgot, if I ever knew, that the undocumented side effect of adding --version is to ignore all other commands!

So I am pleased to confirm that Clang version 8.1.0 and 9.0.0 works nicely for the latest draft C++ standard, building a sample of Boost.Math and Boost.Multiprecision.

using the default clang++.exe dynamic linker uses the MSVC linker., but i have also used the new LLD linker.

I have the compiler unzipped to Compiler executable directory : C:\LLVM\clang-900\LLVM

and copied an existing antique Clang version renaming it to clang900 with these new executables:

C compiler clang.exe
C++ compiler clang++.exe
Linker for dynamic links  clang++.exe 

Linker for static libs : lld-link.exe 

Compiler options-  "std=c++2a" for latest C++ standard


-------------- Build: Debug_clang900 in numeric_limits_snips (compiler: LLVM Clang 900 Compiler)---------------

clang++.exe -Wall -fexceptions -g -std=c++2a --verbose -I..\..\..\boost -c I:\boost\libs\multiprecision\example\numeric_limits_snips.cpp -o obj\Debug\boost\libs\multiprecision\example\numeric_limits_snips.o
clang++.exe  -o bin\Debug\numeric_limits_snips.exe obj\Debug\boost\libs\multiprecision\example\numeric_limits_snips.o  -v 
clang version 9.0.0 (tags/RELEASE_900/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\LLVM\clang-900\LLVM\bin
 "C:\\LLVM\\clang-900\\LLVM\\bin\\clang++.exe" -cc1 -triple x86_64-pc-windows-msvc19.24.28207 -emit-obj -mrelax-all -mincremental-linker-compatible -disable-free -disable-llvm-verifier -discard-value-names -main-file-name numeric_limits_snips.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -gcodeview -debug-info-kind=limited -momit-leaf-frame-pointer -v -coverage-notes-file "I:\\Cpp\\hello_boost\\numeric_limits_snips\\obj\\Debug\\boost\\libs\\multiprecision\\example\\numeric_limits_snips.gcno" -resource-dir "C:\\LLVM\\clang-900\\LLVM\\lib\\clang\\9.0.0" -I "..\\..\\..\\boost" -internal-isystem "C:\\LLVM\\clang-900\\LLVM\\lib\\clang\\9.0.0\\include" -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Preview\\VC\\Tools\\MSVC\\14.24.28207\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\winrt" -Wall -std=c++2a -fdeprecated-macro -fdebug-compilation-dir "I:\\Cpp\\hello_boost\\numeric_limits_snips" -ferror-limit 19 -fmessage-length 0 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.24.28207 -fdelayed-template-parsing -fno-implicit-modules -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -faddrsig -o "obj\\Debug\\boost\\libs\\multiprecision\\example\\numeric_limits_snips.o" -x c++ "I:\\boost\\libs\\multiprecision\\example\\numeric_limits_snips.cpp"
clang -cc1 version 9.0.0 based upon LLVM 9.0.0 default target x86_64-pc-windows-msvc
#include "..." search starts here:
#include <...> search starts here:
 ..\..\..\boost
 C:\LLVM\clang-900\LLVM\lib\clang\9.0.0\include
 C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.24.28207\include
 C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt
 C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared
 C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um
 C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt
End of search list.


clang version 9.0.0 (tags/RELEASE_900/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\LLVM\clang-900\LLVM\bin
 "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Preview\\VC\\Tools\\MSVC\\14.24.28207\\bin\\Hostx64\\x64\\link.exe" "-out:bin\\Debug\\numeric_limits_snips.exe" -defaultlib:libcmt "-libpath:C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Preview\\VC\\Tools\\MSVC\\14.24.28207\\lib\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.18362.0\\ucrt\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.18362.0\\um\\x64" -nologo "obj\\Debug\\boost\\libs\\multiprecision\\example\\numeric_limits_snips.o"

(optionally  to use the new lld linker, one can use the lld.linker by adding linker option

Other linker options "-fuse-ld=lld"

and the compiler option  -flto=thin to ensure the .o file is of the right type.
(but NOT if using default MS linker or get fatal error LNK1136: invalid or corrupt file)
 )

-------------- Build: Debug_clang900 in numeric_limits_snips (compiler: LLVM Clang 900 Compiler)---------------

clang++.exe -Wall -fexceptions -g -std=c++2a --verbose -flto=thin -I..\..\..\boost -c I:\boost\libs\multiprecision\example\numeric_limits_snips.cpp -o obj\Debug\boost\libs\multiprecision\example\numeric_limits_snips.o
clang++.exe  -o bin\Debug\numeric_limits_snips.exe obj\Debug\boost\libs\multiprecision\example\numeric_limits_snips.o  -v -fuse-ld=lld 
clang version 9.0.0 (tags/RELEASE_900/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\LLVM\clang-900\LLVM\bin
 "C:\\LLVM\\clang-900\\LLVM\\bin\\clang++.exe" -cc1 -triple x86_64-pc-windows-msvc19.24.28207 -emit-llvm-bc -flto=thin -flto-unit -disable-free -disable-llvm-verifier -discard-value-names -main-file-name numeric_limits_snips.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -gcodeview -debug-info-kind=limited -momit-leaf-frame-pointer -v -coverage-notes-file "I:\\Cpp\\hello_boost\\numeric_limits_snips\\obj\\Debug\\boost\\libs\\multiprecision\\example\\numeric_limits_snips.gcno" -resource-dir "C:\\LLVM\\clang-900\\LLVM\\lib\\clang\\9.0.0" -I "..\\..\\..\\boost" -internal-isystem "C:\\LLVM\\clang-900\\LLVM\\lib\\clang\\9.0.0\\include" -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Preview\\VC\\Tools\\MSVC\\14.24.28207\\include" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.18362.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.18362.0\\winrt" -Wall -std=c++2a -fdeprecated-macro -fdebug-compilation-dir "I:\\Cpp\\hello_boost\\numeric_limits_snips" -ferror-limit 19 -fmessage-length 0 -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.24.28207 -fdelayed-template-parsing -fno-implicit-modules -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -faddrsig -o "obj\\Debug\\boost\\libs\\multiprecision\\example\\numeric_limits_snips.o" -x c++ "I:\\boost\\libs\\multiprecision\\example\\numeric_limits_snips.cpp"
clang -cc1 version 9.0.0 based upon LLVM 9.0.0 default target x86_64-pc-windows-msvc
#include "..." search starts here:
#include <...> search starts here:
 ..\..\..\boost
 C:\LLVM\clang-900\LLVM\lib\clang\9.0.0\include
 C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.24.28207\include
 C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt
 C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared
 C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um
 C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt
End of search list.


lang version 9.0.0 (tags/RELEASE_900/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\LLVM\clang-900\LLVM\bin
 "C:\\LLVM\\clang-900\\LLVM\\bin\\lld-link" "-out:bin\\Debug\\numeric_limits_snips.exe" -defaultlib:libcmt "-libpath:C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Preview\\VC\\Tools\\MSVC\\14.24.28207\\lib\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.18362.0\\ucrt\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.18362.0\\um\\x64" -nologo "obj\\Debug\\boost\\libs\\multiprecision\\example\\numeric_limits_snips.o"

in case these are helpful to others.

This latest version, with many bug fixes, and many new features available, including exciting constexpr compile-time computations, will be be over interest to many users and I'd like to see it in the next release. 

(The only feature Clang lacks is the 128-bit floating-point option available as quadmath assembler-coded with gcc.  This permits much faster 128-bit FP computation compared to the Boost.Multiprecision C++ software implementation.  You can still get the same ~36 decimal digit precision   :) )

Thanks for your helpful suggestions.   Paul

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
This latest version, with many bug fixes, and many new features available, including exciting constexpr compile-time computations, will be be over interest to many users and I'd like to see it in the next release. 
Offtopic: Haha, I don't understand why people find constexpr, consteval, constwhatever to be exciting. It is pathetic. (pathetic in this case is really mild word) :)

Ontopic: What do you really want integrated in C::B? Can you clarify? Most compilers are defined using xml files. I think even the auto-detection is done with xml files.

p.s. Please use code or quote tags (the # or the text-bubble buttons in the UI for posting on the forum). It will make your posts a lot more readable.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline pabristow

  • Multiple posting newcomer
  • *
  • Posts: 75
Quote
Offtopic: Haha, I don't understand why people find constexpr, consteval, constwhatever to be exciting. It is pathetic. (pathetic in this case is really mild word) :)

Well I am proud to be pathetically excited with constexpr, consteval and everything const  :)

And moreover, I can confirm that GCC 9.2 kindly provided by Brecht Sanders at winlibs.com standalone build of GCC and mingw-w64 for Windows works very nicely with Codeblocks 17 on Windows 10 and this version of GCC provides some exciting (to those constexpressionable) new features for compile-time computation.