2012-03-16 33 views
5

我有一个makefile,可以用g ++ 4.6编译我的项目。在Makefile中使用Clang ++代替G ++

#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铛抛出一些比较密集的错误有关的iostream没有找到正确的ARGS或用东西后,许多其他错误(但这是“根”的错误)一起。

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)> 

这是我的生成文件的问题,还是真的可以在这个简单的编译区别?

使用铛2.9。

注:那铿锵抱怨该生产线是#include <iostream>

+0

我不是一个C++高手,但[此页](http://clang.llvm.org/cxx_status.html)似乎表明,铛2.9不100%准备好C++ 0x - 也许这是问题的一部分? – 2012-03-16 06:11:29

+0

它没有在C++ 0x问题上崩溃,它在包含iostream时崩溃我认为 – soandos 2012-03-16 06:11:58

+1

错误消息中的路径看起来像你得到g ++ 4.6的头文件而不是clang的头文件。 g ++头文件倾向于使用gcc特定的扩展名和可能不适用于clang的东西。 – 2012-03-16 06:28:13

回答

0

如果你在OS X狮子(10.7)和山狮(10.8),使用 'C++'(在/ usr/bin中/ C++ )而不是直接使用'clang ++'。尽管一个是另一个符号链接,但clang有一些智能来设置正确的路径和编译器选项,以便在使用C++时做更多的事情。

+0

我在windows上 – soandos 2012-11-22 02:32:10

1

这是一个老问题,但如果其他人在这里绊倒,有一件事要检查是否你使用的是铿锵的标准库。对于您所需要的标志:

-stdlib=libc++ 
+0

如何将其添加到Makefile中? – javadba 2017-03-22 23:26:02