【问题标题】:Using Clang++ in Makefile in place of G++在 Makefile 中使用 Clang++ 代替 G++
【发布时间】:2012-03-16 06:06:53
【问题描述】:

我有一个使用 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 或之后出现的许多其他错误的相当密集的错误(但这是“根”错误)。

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 &lt;iostream&gt;

【问题讨论】:

  • 我不是 C++ 专家,但this page 似乎表明 clang 2.9 还没有 100% 为 c++0x 做好准备——也许这是问题的一部分?
  • 它不会在 c++0x 问题上崩溃,我认为它在包含 iostream 时会崩溃
  • 错误消息中的路径看起来像是您获取的是 g++4.6 的头文件,而不是 clang 的头文件。 g++ 头文件倾向于使用 gcc 特定的扩展和可能不适用于 clang 的东西。
  • 添加 -v 标志让 clang 打印出它使用的所有参数。然后您可以手动运行这些命令并更改选项以查看是否可以构建单个翻译单元,如果可以,则更改生成文件以使用您发现的设置。

标签: makefile g++ clang


【解决方案1】:

这是一个老问题,但万一其他人在这里绊倒,需要检查的一件事是您是否使用了 clang 标准库。为此,您需要标志:

-stdlib=libc++

【讨论】:

  • 如何将它添加到 Makefile 中?
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-12
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-25
    • 2014-03-11
    相关资源
    最近更新 更多