安装的叮当声:
$~/Projects/clang$ sudo apt-get install clang
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
clang
0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded.
Need to get 0 B/3,590 B of archives.
After this operation, 42.0 kB of additional disk space will be used.
Selecting previously unselected package clang.
(Reading database ... 259453 files and directories currently installed.)
Preparing to unpack .../clang_1%3a3.5-23ubuntu1_i386.deb ...
Unpacking clang (1:3.5-23ubuntu1) ...
Processing triggers for man-db (2.7.0.2-2) ...
Setting up clang (1:3.5-23ubuntu1) ...
编译代码:
$~/Projects/clang$ clang hw.cpp
/tmp/hw-70de0d.o: In function `main':
hw.cpp:(.text+0x8): undefined reference to `std::cout'
hw.cpp:(.text+0x1a): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/hw-70de0d.o: In function `__cxx_global_var_init':
hw.cpp:(.text.startup+0x10): undefined reference to `std::ios_base::Init::Init()'
hw.cpp:(.text.startup+0x16): undefined reference to `std::ios_base::Init::~Init()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
源代码:
#include<iostream>
int main()
{
std::cout<<"Hello,World!\n";
}
使用 clang 还需要什么?
答案1
你需要使用clang++
.clang
是C编译器,clang++
是C++编译器。喜欢gcc
。我认为这些编译器在底层基本上是相同的,但是(再次像gcc
),clang++
默认情况下链接到 C++ 库,而clang
没有。因此会出现链接器错误。