How to use clang for windows using mingw headers/libs - c++

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.

Related

Headers for Clang from VS build tools and LLVM

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

Install gcc 4.9 on windows and configure it in Netbeans

Preamble
If anything I wrote is not correct, please be so kind and correct me. I am a php developer mainly - I am not into this compiling stuff. I know there are a lot of topics around the www but they seems to be either old/outdated, very complex or links to a bunch of files on sourceforge (I have no clue what files I should download and what to do with them after downloading them).
Searching a couple of days by now
I am researching for a couple of days by now and tried different compilers and settings but I don't get a standalone executable for a c++14 programme.
First compiler
The first compiler I used was cygwin. I was able to compile it with c++14 but on other computers cygwin had to be installed as well as a cygwin dll was missing. I googled and figured out that programmes compiled using Cygwin requires this dll but cannot be included to the programme itself - or did I missed something?
Current compiler
I then switched to MinGW which seems to be a better choice as it allows to compile standalone executables which is correct as I am able to do so. Well, the MinGW setup I downloaded from http://www.mingw.org/ installed among other the gcc version 4.8.1. I need 4.9.1 for c++14.
As the title says I want to configure it in Netbeans but if there is a proper tutorial for a command line compiling it's no problem either but I try to avoid using another IDE as we use it at work, too.
drangon.org
I also heard about http://www.drangon.org/mingw/ but there are tons of links linking to similiar stuff.
My goals
Get a better understanding about gcc and this compiling stuff in general.
Install gcc 4.9.1 (preferred into MinGW as it's currently installed)
Configure it in Netbeans 8.
I suggest you to try MinGW-w64. (Download.)
It's similar to MinGW, but have better multitreading support, can easily compile x64 applications, and what's more important, at this moment it uses GCC 4.9.2.
By the way, MinGW applications require some .dlls to work too. Usually you just provide these libraries with your application, but another option is to add -static flag at linking phase. Applications that are compiled with it do not require any external library files (unless you're using 3rd party libraries that don't support static linking).

Getting LLVM and Clang from downloaded sources and Visual Studio 2013

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.

Minimal GCC C++ Compiler

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

Installing C++ Boost library on Windows without Visual Studio

I would like to install Boost library without the need of Visual Studio compiler, preferably by downloading the pre-compiled binaries. We are working on a cross-platform C++ project in Eclipse, so VS is out of option.
About a year ago, I found an installer, but it does not longer exists.
The best match I have found so far is from:
http://www.boostpro.com/download/
but it seems like this one includes a lot of stuff related to VS.
If there is no installer available, is there an easy way of compiling it like the on *NIX platforms?
(I know that the majority of the library is header-only, but I would like some parts which are not)
Whichever toolchain that you are going to use on Windows, you can use that toolchain to compile Boost easily.
For example, if you use Eclipse CDT for C++ on Windows, you can use either MinGW or Cygwin toolchain. Then simply start the command prompt that has those toolchains (make, gcc, ...) in your path. Go to the Boost folder you downloaded. Run the bootstrap file to generate bjam. Then run bjam.
On a side note, if you want a cross-platform C++ project, you don't have to use a cross-platform IDE. You can use CMake as your build generator and then use any IDE you want.
One option is to get the full Boost source and then compile your own application to statically link in everything from Boost. If you manage to do this correctly, there will be no need to bundle the Boost binaries on any platform.