Building a project with CMake, Ninja and Clang++ without MSVC - windows

I'm currently working on a C++ project that build successfully on Linux using CMake, Make & GCC, and also on Windows using CMake & VS2015.
For some reason, i'd like to build it using the same toolchain everywhere, so i planned to use CMake, Clang & Ninja.
I started to try to build it on Windows, but i did not find any documentation to build using libc++ and without anything from the MSVC toolchain.
Am I forced to install MSVC build tools in order to build with CMake & Clang ?

Use a MinGW-w64 of GCC on Windows (e.g. the one from http://winlibs.com, or any other one listed at http://mingw-w64.org/).
If you combine this with the MSYS2 shell (http://www.msys2.org/), you can build a lot using the same tools as on Linux (autoconf, CMake, meson, ...).

Related

Integrate CLion and Android NDK

Recently I've found CLion. I'm trying to configure it to work with Android ndk:
I want it to use the ndk sources and headers.
I want it to use the gcc and g++ compiler in the ndk.
I want it to use my makefile and not cmake.
Couldn't achieve those three targets, hope you can help me :).
By the way I'm using android ndk r10e if it matters.
You can set up CLion to build for android by doing the following:
Install the NDK Standalone Toolchain (https://developer.android.com/ndk/guides/standalone_toolchain.html)
In CLion Preference/Settings under Build, Execution, Deployment > Toolchains, add a new toolchain for ARM, set the C compiler path to $NDK_TOOLCHAIN_PATH/arm/bin/arm-linux-androideabi-clang, set the C++ compiler path to $NDK_TOOLCHAIN_PATH/arm/bin/arm-linux-androideabi-clang++, and if you're on Windows, set the MinGW path. The toolchain tab is a fairly new feature to Clion so make sure you have a recent version of Clion.
Repeat step 2 for any other architectures you want to support
Go to Build, Execution, Deployment > CMake. Add a new profile for ARM. Set the toolchain to the ARM toolchain and set the CMake options to
-DCMAKE_CXX_FLAGS="-fPIE -fPIC -lstdc++"
-DCMAKE_AR="$NDK_TOOLCHAIN_PATH/arm/bin/arm-linux-androideabi-ar"
-DCMAKE_RANLIB="$NDK_TOOLCHAIN_PATH/arm/bin/arm-linux-androideabi-ranlib"
If you're using a Mac you will need these too in order to tell CMake to not use the isysroot option
-DCMAKE_OSX_SYSROOT="/"
-DCMAKE_OSX_DEPLOYMENT_TARGET=""
Repeat step 4 for any other architectures you want to support
When building, set the profile to your desired architecture (instead of Debug/Release).
Ideally, you could specify the entire toolchain (ar, ranlib, etc.) through CLion instead of using CMake options, but I haven't found a way to do so yet.
CLion can work only with CMake-projects. Others are not possible at this stage.
However, you can use Android Studio. It include C++ support based on CLion and works nicely with ndk for sure.

How to build mingw32-make

I've just build a gcc 5.2.0 on windows according to this material:
http://preshing.com/20141108/how-to-install-the-latest-gcc-on-windows/
Everything went well. But then I've tried to build Qt with this newly built gcc and I'm getting an error that there is no mingw32-make. Checked directory and no, there isn't one.
But then I checked previously installed gcc, which was work of TDM, downloaded from:
http://tdm-gcc.tdragon.net/
and yes, in his build there is mingw32-make.
So, the question is, how is it that he has that tool, and many other which are absent in my build are present in his?
if you create from the gcc5.2.0 source, a build then you've just created the gcc compiler with all its necessary files. e.g. gcc-5.2.0.exe, gcc.exe, g++.exe, etc.
NOT the MinGW runtime environment for gcc, which contains the mingw32-make.exe !
if you follow your link from your question here you build it with the cygwin make.exe.
It's better to download the mingw 32 binary runtime environment for gcc
or
MinGW64 runtime environment for gcc
Then you have all the files needed to work with QT.
if you want to create a mingw build from source, you need first a MinGW runtime environment then you can use that to build your own mingw32-make.exe.

target_compile_features fails on MinGW-w64 in MSYS2

I recently installed MSYS2 on Windows, along with the MinGW-w64 toolchain and CMake. Specifically, I used the following packages:
mingw-w64-i686-gcc
mingw-w64-i686-cmake
make
Trouble is, whenever I invoke CMake from within the MSYS2 shell with cmake -G"MSYS Makefiles", it fails with the following:
target_compile_features no known features for CXX compiler
"GNU"
version 4.9.2.
The line in CMakeLists.txt that generates the error is this: target_compile_features(myproject PUBLIC cxx_decltype).
If I run CMake from outside the MSYS2 shell (I also have it installed separately) with the "MinGW Makefiles" generator, the makefile generation succeeds.
Inside MSYS2, the CMake version is 3.2.3. The version outside is 3.3.0.
Is there any way to resolve this issue? Thanks in advance.
There was bug about interaction of compile features mechanism in CMake 3.3 with gcc 4.8+:
https://public.kitware.com/Bug/view.php?id=15443. It have been fixed several months ago. You need that fix being applied.
Run cmake from mingw64_shell.bat or mingw32_shell.bat. CMake will otherwise pickup msys2 GCC rather than a native one.

Getting started with openMP. install on windows

I want to write parallel program in C++ using OpenMP, so I am getting started with OpenMP.
On the other words I am a beginner and I need good OpenMP guide telling how to install it.
Does someone know how to install OpenMP on Windows, then compile and run the program?
OpenMP is not something that you install. It comes with your compiler. You just need a decent compiler that supports OpenMP and you need to know how to enable OpenMP support since it is usually disabled by default.
The standard compiler for Windows comes from Microsoft and it is the Microsoft Visual C/C++ compiler from Visual Studio. Unfortunately its OpenMP support is a bit outdated - even the latest and greatest Visual Studio only supports OpenMP 2.0 (an outdated standard version from 2002). See here for more information on how to use OpenMP in Visual Studio. There are other compilers available as well - both Intel C/C++ Compiler (commercial license required) and GCC (freely available) support newer OpenMP versions and other compilers are available too.
You can start learning OpenMP by visiting the OpenMP web site here. Also there is a great tutorial on OpenMP from Lawrence Livermore National Laboratory available here.
2020 Update: Microsoft now ships Clang for Windows with Visual Studio. Although it is a bit convoluted, one can (ab)use the Clang-cl toolset to produce working 32-bit OpenMP programs. A number of steps are necessary:
If not already installed, add Clang and Clang-cl using the Visual Studio 2019 Installer.
Set the project's platform toolset (project Properties -> General -> Platform Toolset) to "LLVM (clang-cl)".
Enable Clang OpenMP support by adding -Xclang -fopenmp to the compiler options in project Properties -> C/C++ -> All Options -> Additional Options.Important: make sure that OpenMP support is disabled before switching the platform toolset (this is the default for new C++ projects). It seems that VS remembers the setting and still passes /openmp even though the language configuration for Clang has no option for OpenMP. If clang-cl.exe throws error MSB8055 (unsupported /openmp option) during build, set the platform toolset back to "Visual Studio 2019 (vXXX)" and disable the OpenMP support in Properties -> C/C++ -> Language -> Open MP Support, then switch the platform toolset again to "LLVM (Clang-cl)".
Add libomp.lib to the additional libraries in project Properties -> Linker -> Input -> Additional Dependencies.
Add the path to libomp.lib to the linker search path by adding a new entry with value $(LLVMInstallDir)\lib in project Properties -> Linker -> General -> Additional Library Directories.
Add a post-build action that copies LLVM's libomp.dll to the project output directory (without this step, running the executable will fail unless libomp.dll is in the DLL search path). In project Properties -> Build Events -> Post-Build Event -> Command Line:
xcopy /y "$(LLVMInstallDir)\bin\libomp.dll" "$(SolutionDir)$(Configuration)"
Build and run the project.
Note: this is very much likely still unsupported by Microsoft and it only works for x86 projects since the LLVM libraries shipped with VS are 32-bit only.
So here is what I did to finally get OpenMP working on my Windows 10 PC:
Get MinGW - Download and grab what you need to get the basic gcc compiler and the g++ pakage (its really easy to do). You can always run g++ -v to make sure it is up and running
Run mingw-get upgrade --recursive "gcc<4.7.*" "gcc-g++<4.7.*" This is the "Fun" part. Because at this time there was no libgomp library supported in their 4.9.* version my gcc wasn't able to recognize <omp.h> the last support version was 4.7.2 so with this I finally was able to run my openMP
To compile run g++ -fopenmp myOpenMPFile.cpp -o myOpenMP and it will all work from there
gcc -fopenmp myOpenMPFile.cpp -o myOpenMP will also work for C code
I would like to share what I did to get OpenMP working on my Windows 10 PC (things have got even simpler in 2019)
I installed MinGW distribution from here with GCC 8.2.0 compiler. The maintainer of the distribution has already added winpthreads and OpenMP support to GCC.
I compiled my code with -fopenmp flag as follows: g++ -fopenmp main.cpp -o exec
Note: the MinGW distribution provides support for many useful libraries (such as Boost 1.69.0) and other utilities. I found it to be very useful.

Obtaining GCC for OSX with Developer Tools installed

I want to start working with C++0x. I see that GCC 4.7 has a fair amount of functionality available. I already have XCode 3.2 installed in /Developer
I downloaded: http://fileboar.com/gcc/snapshots/LATEST-4.7/gcc-4.7-20110528.tar.bz2
Can I somehow compile this in /opt/gcc-4.7? How do I then work with my path so I can compile with GCC 4.7 from the command-line but have OSX use the version it needs?
OSX does not need gcc to run - the Developer tools are optional. So you only need to choose between gcc's when you compile. In Xcode you chose explicitly the gcc andin Makefiles you can set $(CC) or similar to the full path.
Alternatively rename the gcc-4.7 gcc to gcc-4.7 and use that so gcc is always the Apple one.
For ease of using multiple C++ compilers I use macports (or fink or homebrew) which will compile the compilers with the correct patches and also has a port select command to switch between the C++ compilers

Resources