Questions tagged [clang]

For questions about the clang LLVM compiler front end. For general questions about C, use the C tag.

Usage

This tag should be used for questions specific to clang, an LLVM compiler front end for C-based languages. It should not be used for general questions about C; for those, use the tag.

About

Clang is the LLVM compiler front end for C/C++/Objective-C, which provides fast compiles, useful error and warning messages, an accommodating license and offers an extensible platform for building source level tools.

Why Clang?

The development of a new front-end was started out of a need -- a need for a compiler that allows better diagnostics, better integration with IDEs, a license that is compatible with commercial products, and a nimble compiler that is easy to develop and maintain. All of these were motivations for starting work on a new front-end that could meet these needs.

Current Status

Clang is still under development. Clang is considered to be a production quality C, Objective-C, C++ and Objective-C++ compiler when targeting X86-32, X86-64, and ARM (other targets may have caveats, but are usually easy to fix).

C++ Standards Support

  • C++11 is fully supported in Clang 3.3 and later
  • C++14 is fully supported in Clang 3.4 and later
  • C++17 proposed features are mostly supported in Clang 3.5 and later

Please see the C++ status page for more information.

Related Tags

10121 questions
467
votes
31 answers

Why is this program erroneously rejected by three C++ compilers?

I am having some difficulty compiling a C++ program that I've written. This program is very simple and, to the best of my knowledge, conforms to all the rules set forth in the C++ Standard. I've read over the entirety of ISO/IEC 14882:2003 twice to…
James McNellis
  • 348,265
  • 75
  • 913
  • 977
329
votes
12 answers

Switching between GCC and Clang/LLVM using CMake

I have a number of projects built using CMake and I'd like to be able to easily switch between using GCC or Clang/LLVM to compile them. I believe (please correct me if I'm mistaken!) that to use Clang I need to set the following: SET…
Rezzie
  • 4,763
  • 6
  • 26
  • 33
303
votes
7 answers

How do I print a list of "Build Settings" in Xcode project?

Alternate Titles List of Xcode build variables Print a list of Xcode Build Settings Clang Environment Variables Canonical list of Xcode Environment Variables Is there a Canonical list of Xcode Environment Variables that can be used in Build Rules…
Richard Stelling
  • 25,607
  • 27
  • 108
  • 188
292
votes
7 answers

Clang vs GCC - which produces faster binaries?

I'm currently using GCC, but I discovered Clang recently and I'm pondering switching. There is one deciding factor though - quality (speed, memory footprint, reliability) of binaries it produces - if gcc -O3can produce a binary that runs 1% faster,…
SF.
  • 13,549
  • 14
  • 71
  • 107
275
votes
15 answers

clang error: unknown argument: '-mno-fused-madd' (python package installation failure)

I get the following error when attempting to install psycopg2 via pip on Mavericks 10.9: clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future] Not sure how to proceed and have searched here and…
tino
  • 4,780
  • 5
  • 24
  • 30
217
votes
26 answers

Xcode - ld: library not found for -lPods

I get these errors when I try to build an iOS application. ld: library not found for -lPods clang: error: linker command failed with exit code 1 (use -v to see invocation) Ld…
mrks
  • 5,439
  • 11
  • 52
  • 74
203
votes
5 answers

In CMake, how can I test if the compiler is Clang?

We have a set of cross-platform CMake build scripts, and we support building with Visual C++ and GCC. We're trying out Clang, but I can't figure out how to test whether or not the compiler is Clang with our CMake script. What should I test to see if…
leedm777
  • 23,444
  • 10
  • 58
  • 87
192
votes
5 answers

How to make clang compile to llvm IR

I want clang to compile my C/C++ code to LLVM bitcode rather than a binary executable. How can I achieve that? And if I have the LLVM bitcode, how can I further compile it to a binary executable? I want to add some of my own code to the LLVM bitcode…
pythonic
  • 20,589
  • 43
  • 136
  • 219
189
votes
6 answers

Clang vs GCC for my Linux Development project

I'm in college, and for a project we're using C. We've explored GCC and Clang, and Clang appears to be much more user friendly than GCC. As a result, I'm wondering what the advantages or disadvantages are to using clang, as opposed to GCC, for…
haziz
  • 12,994
  • 16
  • 54
  • 75
175
votes
1 answer

Why is processing an unsorted array the same speed as processing a sorted array with modern x86-64 clang?

I discovered this popular ~9-year-old SO question and decided to double-check its outcomes. So, I have AMD Ryzen 9 5950X, clang++ 10 and Linux, I copy-pasted code from the question and here is what I got: Sorted - 0.549702s: ~/d/so_sorting_faster$…
DimanNe
  • 1,791
  • 3
  • 12
  • 19
170
votes
3 answers

ARC and bridged cast

With ARC, I can no longer cast CGColorRef to id. I learned that I need to do a bridged cast. According clang docs: A bridged cast is a C-style cast annotated with one of three keywords: (__bridge T) op casts the operand to the destination type T.…
Morrowless
  • 6,856
  • 11
  • 51
  • 81
170
votes
21 answers

How to fix linker error "cannot find crt1.o"?

I have a virtual Debian system which I use to develop. Today I wanted to try llvm/clang. After installing clang I can't compile my old c-projects (with gcc). This is the error: /usr/bin/ld: cannot find crt1.o: No such file or directory /usr/bin/ld:…
Stefan Keller
  • 1,703
  • 2
  • 11
  • 5
165
votes
1 answer

What are the differences between -std=c++11 and -std=gnu++11?

What are the differences between -std=c++11 and -std=gnu++11 as compilation parameter for gcc and clang? Same question with c99 and gnu99? I know about C++ and C standards, it's the differences in the parameters that interest me. I've read somewhere…
Klaim
  • 67,274
  • 36
  • 133
  • 188
153
votes
2 answers

GCC -g vs -g3 GDB Flag: What is the Difference?

When compiling C source code with either gcc or Clang, I always use the -g flag to generate debugging information for gdb. gcc -g -o helloworld helloworld.c I noticed that some people recommend -g3 instead. What is the difference between the -g and…
haziz
  • 12,994
  • 16
  • 54
  • 75
151
votes
3 answers

LLVM vs clang on OS X

I have a question concerning llvm, clang, and gcc on OS X. What is the difference between the llvm-gcc 4.2, llvm 2.0 and clang? I know that they all build on llvm but how are they different? Besides faster compiling, what is the advantage of llvm…
dominik
  • 5,745
  • 6
  • 34
  • 45
1
2 3
99 100