How to setup CLion with portable Clang on ubuntu? - c++

I want to test Clang with CLion in ubuntu. By default Clion detects my gcc installation, but I want to use clang instead of gcc. Moreover, I don't want to install clang via apt-get. I have downloaded llvm, clang (3.6.2) binary from llvm website. I want to use that portable clang binaries.
Here is my system setup:
Ubuntu - 14.04
gcc - 4.8.4
llvm clang - 3.6.2 (portable)
CLion - 1.0.4
So how to set up CLion with llvm-clang here?

I got the answer from CLion blog and it works and here it goes.
To provide CMake compiler paths, go to Settings | Build, Execution, Deployment | CMake and pass as CMake options:
-D CMAKE_C_COMPILER=
-D CMAKE_CXX_COMPILER=
In case CMake fails to find some path to clang libs, etc. you can also set there environment variables:
CC=/usr/bin/clang
CXX=/usr/bin/clang++

The FAQ states the following:
At present CLion supports GCC and Clang compilers and is guided by these two to get the libraries and headers paths. In the next releases we are planning to extend the list of compilers available in CLion.
To change the compiler, go to the Cache tab in CMake tool window and set the compiler’s path to the CMAKE_CXX_COMPILER variable. Then press Enter and click the Apply Changes and Reload button

Related

How to change MacOS Default from clang to homebrew gcc

I'm having trouble finding how to change the default c++ compiler from clang to the homebrew version of gcc I have installed. The end goal here is to be able to run a command line gradle build using gcc.
I've checked to make sure that the first directory in the PATH variable is /usr/local/bin as suggested in some places, but it still defaults to clang/LLVM

How to use Clang kit with Qt Creator on Windows?

(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.

What is the sanctioned way to build libc++ for clang on Linux?

Edit/Update/Note: Just let clang use libstdc++. Has been working really well for me so far.
===============================
In the past I have been able to succeed by doing something with cmake, but just now I discovered a buildit script inside the lib directory of the http://llvm.org/svn/llvm-project/libcxx/trunk project tree.
This buildit script appears to not make use of libsupc++ which is what the cmake approach that I took earlier used. For instance, this guide shows one cmake incantation to produce a makefile for libc++, which will be able to take care of compiling and installation.
My question is what is the difference between these different ways to produce the LLVM-libc++ and which one should be used? Will they behave differently?
The buildit script does not appear to provide any help for installation. Are there directions anywhere for how to properly install the library? With my previous libc++ built with cmake, I had to always add -lc++ to the linker flags (and the path with -L), which is not necessary in my OS X makefiles.
The libc++ website has a nice overview of the possible ways to build libc++.
I suggest using CMake + libc++abi.
Also see the Arch Linux User Repository build script, which uses the buildit script. I installed libc++ from that and used it with the Arch Linux Clang package succesfully by using
clang++ -std=c++11 -stdlib=libc++ -lc++abi

How to update GCC in MinGW on Windows?

I'm used to manually install GCC from source before on Ubuntu and it was a painful process. So I really don't want to do repeat this process. Currently, I have MinGW and GCC (4.6.2) installed on my machine. So is there an easy way to update GCC without building it entirely from source? Has anyone done it before can share me some tips?
Update using terminal:
Run the command prompt/terminal (cmd or sh).
Update the package list:
mingw-get update
After updating the package list, run:
mingw-get upgrade
When the command finishes running, all of your packages will be upgraded.
Update using the GUI version:
If you aren't used to the terminal, there is also a GUI version of MinGW called "MinGW Installation Manager", which is normally located at:
C:\MinGW\libexec\mingw-get\guimain.exe
When the GUI is open, tap Installation -> Update Catalogue. This will update the package list.
After that, tap Installation -> Mark All Upgrades. This will select all of the packages which can be upgraded.
Finally, tap Installation -> Apply Changes to apply the upgrades.
Snapshots and release builds of the MinGW http://code.google.com/p/mingw-builds/downloads/list
UPDATE: As of Nov-5-2012, MinGW includes 4.7.2 of the GCC compiler, which is the most current version. I personally will use the MinGW package, since it includes MSYS and other tools, and since it is the defacto standard, I hope that it is better supported. The only drawback is the included GDB does not include Python scripting, but I think that can be updated separately.
I don't know if you can update the GCC in MinGW, but there are alternative projects to MinGW with newer versions of GCC.
The MinGW-builds project provides a package similar to MinGW but with an updated GCC (4.7.2). I extracted the files to c:\MinGW (so I could use the same path) after moving my existing MinGW to another folder. Only MinGW has MSYS, so if you need that (I did) copy the msys folder from the original MinGW.
After installing MinGW-builds, the result of g++ --version:
g++ (Built by MinGW-builds project) 4.7.2
The latest GCC that comes with standard MinGW is currently 4.7.0. I compiled a few simple projects in Code::Blocks, and the latest wxWidgets source, and everything seems to work.
It's worth noting that MinGW-builds includes a Python script enabled version of GDB, in case you want STL pretty printer support, or other GDB Python features.
Another good choice is TDM-GCC, which is a project that hosts an impressive installer that includes an updated GCC compiler (4.7.1) and support tools. It is a standalone package. As far as I can tell, Python scripting is not supported in the GDB that comes with this package.
Finally there is the MinGW-w64 project, which is a fork of MinGW. Rubenvb, who posted an answer to this question, has good standalone packages (in the personal builds folder) based on this project which include an updated GCC (4.7.2). The included GDB seems to be Python script enabled.
if you use MSYS2
just open mingw64-console and type in:
# Update the package database and core system packages with:
pacman -Syu
# If needed, close MSYS2, run it again from Start menu. Update the rest with:
pacman -Su
I have built a more up to date GCC 4.7 (it's built within code freeze, so it should be equivalent with the release). Also, this build contains <thread> support.
32-bit
64-bit
The -gcc_linux package is what you want if you want to use it on Linux. Just extract somewhere and add the mingw??/bin directory to PATH.
PS: There's a native Windows compiler and a Windows Clang build. I suggest using Clang only with one of my GCC 4.6 builds, as it has trouble with GCC 4.7's libstd++. Extract the Clang package in the same directory as the GCC package and it will work out of the box.
The MinGW-w64 build from http://winlibs.com/ has the latest GCC version and requires no installation, just unzip the download. To upgrade you can just replace the mingw32 or mingw64 folder with the new version.
To get latest MinGW64 in Windows: https://sourceforge.net/projects/mingw-w64/?source=typ_redirect
For all platforms: https://mingw-w64.org/doku.php/download
You just need to update your g++ compiler if its not.
First problem can be solved through this:
Update using the GUI version:
If you aren't used to the terminal, there is also a GUI version of MinGW called "MinGW Installation Manager", which is normally located at:
C:\MinGW\libexec\mingw-get\guimain.exe
When the GUI is open, tap
Installation -> Update Catalogue
. This will update the package list.
After that, tap
Installation -> Mark All Upgrades
. This will select all of the packages which can be upgraded.
Finally, tap
Installation -> Apply Changes
to apply the upgrades.
2nd Problem could be that if you didn't updated the path of mingw in environment variables.

target mingw with cygwin

I've tried building the gtest 1.5 library for MinGW
Using MSys to configure and then make results in a lot of errors, most about Win32API
On their website it says mingw is not supported but in the FAQ it is specified that a user managed to build it for mingw from cygwin configuring like this:
./configure CC="gcc -mno-cygwin" CXX="g++ -mno-cygwin"
This configure fails for me when running a sanity check for the C++ preprocessor ... something about "/lib/cpp".
I've tried a cygwin install with only mingw-gcc4 (4.3.4) and a cygwin install with mingw-gcc4 (4.3.4) and cygwin's own gcc (~3.4.4).
Generally, the library could be smoothly configured and built with cygwin gcc (3.4.4) using the flags you have specified above. You should only validate that gcc-mingw, gcc-mingw-core & gcc-mingw-g++ packages are installed in cygwin. There is no need in mingw-gcc4