Installed clang++3.6 on Ubuntu, can't select as alternative
These work for me:
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-3.6 100
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-3.6 100
Switching between GCC and Clang/LLVM using CMake
CMake honors the environment variables CC
and CXX
upon detecting the C and C++ compiler to use:
$ export CC=/usr/bin/clang
$ export CXX=/usr/bin/clang++
$ cmake ..
-- The C compiler identification is Clang
-- The CXX compiler identification is Clang
The compiler specific flags can be overridden by putting them into a make override file and pointing the CMAKE_USER_MAKE_RULES_OVERRIDE
variable to it. Create a file ~/ClangOverrides.txt
with the following contents:
SET (CMAKE_C_FLAGS_INIT "-Wall -std=c99")
SET (CMAKE_C_FLAGS_DEBUG_INIT "-g")
SET (CMAKE_C_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG")
SET (CMAKE_C_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2 -g")
SET (CMAKE_CXX_FLAGS_INIT "-Wall")
SET (CMAKE_CXX_FLAGS_DEBUG_INIT "-g")
SET (CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O2 -g")
The suffix _INIT
will make CMake initialize the corresponding *_FLAGS
variable with the given value. Then invoke cmake
in the following way:
$ cmake -DCMAKE_USER_MAKE_RULES_OVERRIDE=~/ClangOverrides.txt ..
Finally to force the use of the LLVM binutils, set the internal variable _CMAKE_TOOLCHAIN_PREFIX
. This variable is honored by the CMakeFindBinUtils
module:
$ cmake -D_CMAKE_TOOLCHAIN_PREFIX=llvm- ..
Setting _CMAKE_TOOLCHAIN_LOCATION
is no longer necessary for CMake version 3.9 or newer.
Putting this all together you can write a shell wrapper which sets up the environment variables CC
and CXX
and then invokes cmake
with the mentioned variable overrides.
Also see this CMake FAQ on make override files.
How do you make clang++ not warn about variable length arrays?
error: variable length arrays are a C99 feature [-Werror,-Wvla-extension]
int a[argc];
^
1 error generated.
clang++
helpfully tells you what flags generated the diagnostic. Just "invert" the flag, in this case: -Wno-vla-extension
.
clang++ under QtCreator can't work with c++11
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
LIBS += -stdlib=libc++
QMAKE_CXXFLAGS += -stdlib=libc++
QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -mmacosx-version-min=10.7
QMAKE_LFLAGS += -mmacosx-version-min=10.7
I can compile the codes by this .pro file
But there are warning when you play with Qt library
ld: warning: directory not found for option ‘-F/Users/yyyy/Qt5.0.1/5.0.1/clang_64/qtbase/lib’
After some research, I find out this is a bug of Qt5
It is ok if you ignore this warning message even it is annoying
Swift on Linux: Make very first step work
I had the exact same problem. It turns out that I had added the ppa:ubuntu-toolchain-r/test repo in order to install g++-4.9 on my Mint distro (17.2). Once I purged the repository and restored various libraries to their original versions, swift finally worked for me.
Specifically, I had to run
sudo apt-get install ppa-purge
sudo ppa-purge -d trusty ppa:ubuntu-toolchain-r/test
While cleaning up, ppa-purge was complaining that in order to resolve conflicts, it would have to remove quite a few packages it could not find in the Ubuntu Trusty repo (including really core ones like build-essential, xorg, gcc, x11-xserver-utils...), so I made a note and reinstalled these right away after the purge. Just be very careful.
I think some of the libraries overridden when installing g++ 4.9 were creating a conflict. I've verified all this on a fresh Mint install too.
How can I install clang-format in Ubuntu?
clang-format is not available in the ubuntu-precise 12.04 but it is available in ubuntu
saucy http://packages.ubuntu.com/saucy/clang-format-3.4.
in order to find this package with the apt-cache we have to add below list into our repository list. Actually below list is generated for the singapore servers but if you want to look for your own country you can use http://repogen.simplylinux.ch/generate.php
After generating your list, you have to add them into your repository, you can learn how to do that by looking to here. https://help.ubuntu.com/community/Repositories/CommandLine
The list of packages are;
deb http://sg.archive.ubuntu.com/ubuntu/ saucy main restricted universe multiverse
deb-src http://sg.archive.ubuntu.com/ubuntu/ saucy main restricted universe multiverse
deb http://sg.archive.ubuntu.com/ubuntu/ saucy-security main restricted universe multiverse
deb http://sg.archive.ubuntu.com/ubuntu/ saucy-updates main restricted universe multiverse
deb http://sg.archive.ubuntu.com/ubuntu/ saucy-proposed main restricted universe multiverse
deb http://sg.archive.ubuntu.com/ubuntu/ saucy-backports main restricted universe multiverse
deb-src http://sg.archive.ubuntu.com/ubuntu/ saucy-security main restricted universe multiverse
deb-src http://sg.archive.ubuntu.com/ubuntu/ saucy-updates main restricted universe multiverse
deb-src http://sg.archive.ubuntu.com/ubuntu/ saucy-proposed main restricted universe multiverse
deb-src http://sg.archive.ubuntu.com/ubuntu/ saucy-backports main restricted universe multiverse
Then you should search clang-format with below command first
sudo apt-cache search clang-format
Then, you can install which version you want to install such as;
sudo apt-get install clang-format-3.3
Related Topics
How to Use "Py" Instead of "Python" at the Command Line in Linux
How to Make a Built-In Device Driver in Linux
How to Replace Just One Newline Between > and < in Unix
How to Check All Columns Data Types of Table Using Awk Script
Issue While Validating Bash Script
Bash - Find Files Older Than X Minutes and Move Them
How to Grep One String Occuring Multiple Times from Same File
How to Write Multiple Line String Using Bash with Variables
How to Format My Grep Output to Show Line Numbers at the End of the Line, and Also the Hit Count
How to Force a Cifs Connection to Unmount
How to Redirect the Output of an Application in Background to /Dev/Null
How to Get the Current Network Interface Throughput Statistics on Linux/Unix
How to Clear All History in Linux/Ubuntu Terminal or Bash Permanently
How to Delete History of Last 10 Commands in Shell
Graphical Diff Programs for Linux
How to Delete Multiple Files at Once in Bash on Linux