Clang とは
Clang は C や C++ などのC言語系のコンパイラ。
Clang C Language Family Frontend for LLVM
The Clang project provides a language front-end and tooling infrastructure for languages in the C language family (C, C++, Objective C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. Both a GCC-compatible compiler driver (clang) and an MSVC-compatible compiler driver (clang-cl.exe) are provided. You can get and build the source today.
今回の動作確認環境
macOS Catalina + Apple clang version 11.0.3
$ clang -v
Apple clang version 11.0.3 (clang-1103.0.32.59)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.15.4
BuildVersion: 19E287
C で Hello World
以下の hello.c ファイルを用意。
#include <stdio.h>
int main(int argc, char **argv) {
printf("Hello, world,\n");
}
コンパイル・リンクして実行。
$ clang hello.c
$ ./a.out
Hello, world,
C++ で Hello World
以下の hello.cpp ファイルを用意。
hello.cpp
#include <iostream>
int main(int argc, char **argv) {
std::cout << "Hello, world." << std::endl;
}
コンパイル・リンクして実行。
$ clang++ hello.cpp
$ ./a.out
Hello, world.