---
title: Clang不支持在使用'-o'指定输出时直接添加头文件
description: "```"
url: https://www.hikunpeng.com/document/detail/zh/kunpengdevps/compilation/ug-bisheng/kunpengbisheng_06_0045.html
sourcePath: /source/zh/kunpengdevps/compilation/ug-bisheng/kunpengbisheng_06_0045.html
indexId: d7ff0fee50271ddcaeb0d4f46178a911e7fb53a9eabd363af9736a0060cae19874
---
# Clang不支持在使用'-o'指定输出时直接添加头文件

#### 错误信息

```
clang test.h test.c -o test 
clang: error: cannot specify -o when generating multiple output files
```


#### 问题介绍

Clang不支持在使用'-o'指定输出文件时直接添加头文件，但允许在编译命令中使用预编译头文件，以减少编译时间。

```
$ cat test.c  
#include "test.h"
```

生成预编译头文件的命令：

```
clang -x c-header test.h -o test.h.pch
```

可以通过添加 '-include' 命令使用预编译头文件：

```
clang -include test.h test.c -o test
```

Clang会先检查test.h对应的预编译头文件是否存在，如果存在，则会使用对应的预编译头文件对test.h进行处理；如果不存在，Clang会直接处理test.h的内容。

若需在Clang编译命令中保留头文件，则可以通过添加命令'-include'的方法使其通过编译。详情参考Clang用户手册(https://clang.llvm.org/docs/UsersManual.html)。


#### 解决方案

避免在Clang的编译命令中直接添加头文件，或者按照上述方法使用预编译功能。
