预编译头文件clang重新定义错误

时间:2021-07-04 23:02:19

标签: c++ clang

尝试在此处创建一个可重复性最低的示例:

#include "test.hpp"

int main() {
    printMe();
    return 0;
}

假设test.hpp如下:

#include <iostream>
#include <vector> 
#include <unordered_map>
#include <unordered_set>
#include <string>

void printMe(){
    std::cout<<"hey me you"<<std::endl;
}

现在在终端中运行

clang++ -std=c++2a test.hpp

哪个成功并创建了 test.hpp.gch,但是当我运行时:

clang++ main.cpp -o main -std=c++2a -stdlib=libc++ -include-pch test.hpp.gch

我明白了:

In file included from main.cpp:1:
./test.hpp:7:6: error: redefinition of 'printMe'
void printMe(){
     ^
./test.hpp:7:6: note: previous definition is here
void printMe(){
     ^

为什么会这样?

0 个答案:

没有答案