I was experimenting with different compilers, build managers and IDEs for my new project in C++. I am using VSCode(v1.52) on a windows 10 machine. I installed VS build tools 2019 and also included C++ Clang Compiler for Windows and C++ Clang-cl for v142 build tools (x64/x86). The project uses CMake as build manager and a plug-in CMake tools have been installed as well. Setup works fine as it is now.
However, I just want to know what are the differences to include Clang compiler from VSCode build tools 2019 and from LLVM. Does Clang that comes with VSCode build tools uses its own headers or the headers from VS? I do not want to use if Clang uses headers from VS..!
VSCode build tools (C++ Clang tools for Windows) will link the Clang compiler with Microsoft implementation of the Standard Library
Also, VSCode build tools has a component called: "C++ Clang-cl for v142" that gives you the freedom of using your own Compiler/Settings
Regarding header files, on Windows you should use clang with either GCC (Open Source) or MSVC header files.
I could not find the exact source of the header files in VS Build tools. However, as said above, it will link the compiler with Microsoft STL.
To install Clang with GCC header files (Works on VsCode):
go to https://www.msys2.org/ and install mysys2
then open mysys2 terminal and copy those commands to install Clang:
pacman -S mingw-w64-x86_64-clang
pacman -S mingw-w64-x86_64-clang-tools-extra
dont forget to add \msys64\mingw64\bin to the SYSTEM PATH variable
I have also made a video, with step by step: https://youtu.be/5OSO8IRlyXc
Related
I want to generate vxworks 6.x makefiles and workspace via CMake, and there is no support for VxWroks in CMake. How do I create a relevant generator for my platform anf the correct toolchain?
I'm new to CMake. I managed to create some test project that generate for windows VS 2015 and Ubuntu.
I tried to create one for VxWorks 6.x with GNU and DIAB compiler, but there is no support for it in CMake.
I read about something called toolchain, cross-compiling and platform files (.cmake) but I don't understand how to write it and where to put it.
I saw many examples in the internet but didn't understand if I need to rebuild the CMake with the new platform files or just reference to them form the toolchain or from CMakeLists.
I'm using the gui version of CMake 3.14.
I setting the generator as: Eclipse CDT4 - Unix Makefiles.
When I choosing the option of cross-compiling and provide name VxWorks, version, c++ compiler (gnu/4.1.2-vxworks-6.6/x86-win32/bin/c++ppc.exe), it write that the compiler is unknown and that I need to create Platform/VxWroks. It cannot build a simple test program.
I saw some post of someone who succeeded to create all required files :
Do (Cross-compile) platform files require an include guard?
But I couldn't download some examples to test it and a tutorial of how to do it.
I would like to be able to cgreate a generator with CMake for VxWorks 6.x to cimpile libraries and exacutable (.vxe) but don't know what to do.
CMake is not well supported in VxWorks 6, but CMake is supported from the Workbench/Eclipse GUI environment in VxWorks 7. Neither version supports command line cmake, e.g. "cmake ."
(this question similar to this one but is not the same)
I'm using QtCreator on Windows platform, usually with vc toolchain.
sometimes with MinGW-W64, so for now, I'd like to try clang for some reasons.
unlike the post above - I don't use Qt library , just qtcreator as IDE, so I suppose I don't need to re-build it and QtCreator for a using clang kit, is it correct?
there are a few questions about that:
CLang distribution doesn't contain platform or even c/c++ runtime library, should i use it from vc kit? or/and MinGW runtime? how to switch between?
Correct my understanding please if it's wrong - for Win platform, clang has two options to use: 1) normal use - clang.exe ,as on any other platform 2) clang-cl.exe - additional layer which "looks like" cl.exe, and just parses cl command line keys and calls normal clang.
as I understand there is no LLDB for Windows platform , can I use GDB or CDB depends of the used runtime lib and binary format of the executable?
and finally - how to configure all this in qtcreator?
The following steps apply only to MSYS2 64-bit installation of QT Creator 4.5.1 (install instructions here), where you also have MinGW-w64 and mingw32-make installed on MSYS2; and you are building a non-QT C or C++ application.
These instructions use QMake, because QBS doesn't support MSYS2 clang. Well, QMake doesn't support it either, but I did figure out how to add support to QMake and I didn't figure out QBS.
There is QMake support for MSVC-clang but it outputs MSVC makefiles, so you can't build it with MSYS2 make. So that does not apply to us.
Install clang with pacman. I used pacman -Ss mingw-w64-x86_64-clang, your flavour may vary.
Add support for clang to QMake:
In the MSYS2 shell, go into /msys64/mingw64/share/qt5/mkspecs/
Do cp -a win32-g++ win32-clang-msys
Edit win32-clang-msys/qmake.conf and change gcc to clang, and g++ to clang++ (2 places each)
In the same file, take out -fno-keep-inline-dllexport -mthreads which are not supported by clang.
In QT Creator, set up a new Kit:
Go to Manage Kits.
Add a Custom Compiler for C and browse to the installed path (/mingw64/bin/clang.exe under your MSYS2 install).
Add a Custom Compiler for C++ as clang++.exe in the same place)
Add a manual Kit called Clang and set those two compilers as its compilers.
In the manual kit config set "Qt mkspec" as win32-clang-msys
Set "QT Version" to something. Even though I am using a non-QT project, the IDE doesn't like using the kit if "Qt version" is set to None.
Now you can attempt to build your project with the Clang kit and QMake.
I initially tried with QBS and the build failed due to this bug . But the build commands do succeed if I copy-paste them and cut out the bogus -target switch. So for QBS users I guess you have to switch to QMake in the meantime until they fix that bug.
Troubleshooting: I sometimes got an error Project ERROR: failed to parse default search paths from compiler output. This is a problem with QMake's lack of support for clang. The error tended to not occur if I built in a subdirectory of the .pro file, but did occur if I built in a sibling directory.
As a workaround: go back into win32-clang-msys/qmake.conf. Change the first clang back to g++. Then "Run Qmake" (from QT creator or commandline), then change it back. The first time you run QMake it writes the file .qmake.stash and then does not need to generate it again. The contents of this file were bogus for me but building seemed to work anyway.
Undefined references: I found that linking with -static produced a bunch of undefined references to __imp__cxa_ names. Not sure what the problem is here but maybe related to the bug with generating .qmake.stash. I guess the Qt developers would need to officially add non-MSVC Clang support to QMake.
Multiple definitions: The CLang linker gave multiple definitions for inline DLLexport functions. I found no workaround yet for this; g++ has -fno-keep-inline-dllexport to avoid this problem but CLang 5 does not support that flag.
I just downloaded the sources of LLVM and Clang as compressed files.
The files I have so far are:
cfe-3.5.0.src.tar
compiler-rt-3.5.0.src.tar
libcxx-3.5.0.src.tar
libcxxabi-3.5.0.src.tar
llvm-3.5.0.src.tar
I need to configure LLVM and Clang using Windows 8.1 using Visual Studio 2013.
I ask this question because the tutorials I have consulted so far uses svn, but having the sources from compressed files I not have a clear vision of what should be the directory tree in order to cmake work properly.
The directory structure should be:
llvm/
projects/
compiler-rt/
libcxx/
libcxxabi/
tools/
clang/
I'm not sure how far along libc++ support for Windows is, as I just use MSVC's implementation for ABI compatibility.
Compiling llvm framework (llvm, clang, libc++, etc...) with Visual Studio 2013 is not so dificult.
Download the sources
Descompress the sources
Move the decompressed folders to their place in the llvm source tree. (ex: cfe-version goes in llvm\tools directory with name clang. This king of info could be obtained from the CMakeFile.txt files (ex: add_llvm_external_project(clang) in the file `llvm\tools\CMakeFile.txt). The CMakeFile.txt are the files that instruct cmake program how to generate the projects (ex: Makefile, VS projects, XCode projects... for compile llvm)
Create a directory where to save the vs2013 projects
Generate the VS2013 projects (ex: being inside the previous directory execute: cmake llvm_sources -G "Visual Studio 12" where llvm_sources is the root directory of the llvm sources.
Open the project and compile (could take long to compile 30min or more)
Notes: some projects (ex: lldb) could need additional dependencies (ex: python c headers for bindings).
One of the problems of clang when compiling from sources is that the directory path of the include headers that clang use (ex: std library headers), are fixed in the source code in: llvm\tools\clang\lib\FrontEnd\InitHeaderSearch.cpp, in the case of compiling llvm with VS2013, by default it use the MS std headers.
Compiling almost every mid size program with clang using the MS header would give you error with MS extensions not supported yet by clang, with non-conforming c++ (that vc++ accept as valid) and other sort of problems, this is the case of various libraries of boost also (when using the MS headers).
Better success history for me was compile using this same procedure with MinGW for windows and using the MinGW headers. In this case most probably need to modify by hand the HeaderSearch file for clang to search for the header (the last versions of clang don't have search path for the last versions of gcc, at least in the stable version 3.5.0).
Using this method, I successfully compile clang 3.5.0 with MinGW with GCC 4.9.1 in Windows 8.1.
I downloaded the clang for windows binary package from the website. It provides some nice VS/MSBuild integration by allowing to build VS projects using clang instead of MSVC. However, I notice that it still uses the MSVC C Library and also the MSVC linker (link.exe). Also, including any C++ STL headers like string or iostream causes build errors.
My question is: Is it possible to use full clang/llvm toolchain along with some non-Microsoft libraries (like libc++, mingw etc.) to build a native Windows binary? Doing all of this from within VS is a bonus but even from command-line would be fine.
I'm trying to minimize the resources required to compile and run c++ code with GCC. I downloaded DevC++'s portable version but I'm looking more towards what files do I need to ONLY run gcc via command prompt and compile against all standard libraries. I'm not interested in Windows applications, only command prompt.
Is there an already stripped version of GCC out there? And if not, would anyone be able to lend me a hand
*I know of CygWin, and MinGW already, I'm looking for the bare minimals to using the cpp compiler for GCC. Like Tiny C where the entire functioning compiler and libraries is under 200 kilobytes, I'm looking to emulate that workflow with a cpp compiler.
MinGW
MinGW, a contraction of "Minimalist GNU for Windows", is a minimalist development environment for native Microsoft Windows applications.
Primarily intended for use by developers working on the native MS-Windows platform, [...] MinGW includes:
A port of the GNU Compiler Collection (GCC), including C, C++, ADA and Fortran compilers;
GNU Binutils for Windows (assembler, linker, archive manager)
A graphical and a command-line installer for MinGW and MSYS deployment on MS-Windows