在Makefile中使用Clang ++代替G ++

时间:2012-03-16 06:06:54

标签: makefile g++ clang

我有一个使用g ++ 4.6构建我的项目的makefile。

#specify the compiler  
GXX=g++ -std=c++0x

# Specifiy the target  
all: linkedList

# Specify the object files that the target depends on  
# Also specify the object files needed to create the executable  
linkedList: StudentRecord.o Node.o LinkedList.o  ListMain.o
    $(GXX) StudentRecord.o Node.o LinkedList.o  ListMain.o -o linkedList

# Specify how the object files should be created from source files  
LinkedList.o: LinkedList.cpp
    $(GXX)  -c  LinkedList.cpp

ListMain.o: ListMain.cpp
    $(GXX)  -c  ListMain.cpp

StudentRecord.o: StudentRecord.cpp
    $(GXX)  -c  StudentRecord.cpp

Node.o: Node.cpp
    $(GXX)  -c  Node.cpp

当我将第一行更改为GXX = clang++ -std=c++0x时,clang会抛出一些相当密集的错误,关于iostream在此之后没有找到正确的args或其他许多错误(但这是" root&#34 ;错误)。

In file included from /usr/include/c++/4.6/iostream:39:
In file included from /usr/include/c++/4.6/ostream:39:
In file included from /usr/include/c++/4.6/ios:40:
In file included from /usr/include/c++/4.6/bits/char_traits.h:40:
In file included from /usr/include/c++/4.6/bits/stl_algobase.h:65:
In file included from /usr/include/c++/4.6/bits/stl_pair.h:60:
In file included from /usr/include/c++/4.6/bits/move.h:53:
/usr/include/c++/4.6/type_traits:630:59: error: '_Tp' does not refer to a value
    : public integral_constant<bool, __is_standard_layout(_Tp)>

这是我的makefile的问题,还是在这个简单的编译中确实存在差异?

使用clang 2.9。

注意: clang抱怨的行是#include <iostream>

2 个答案:

答案 0 :(得分:1)

这是一个老问题,但如果其他任何人在这里遇到障碍,要检查的一件事是你是否正在使用clang std lib。为此你需要标志:

-stdlib=libc++

答案 1 :(得分:0)

如果您使用的是OS X Lion(10.7)或Mountain Lion(10.8),请使用'c ++'(/ usr / bin / c ++)而不是直接使用'clang ++'。即使一个是另一个的符号链接,clang也有一些聪明的方法来设置正确的路径和编译器选项,以便在使用c ++时做更多的事情。