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(){
^
为什么会这样?
解决方案
推荐阅读
- javascript - Slider Revolution 无法更改文本/按钮颜色
- firefox-addon - Firefox(Hunspell)在拼写检查单词之前如何以及如何清理文本?
- windows - Windows Defender 根据扫描结果创建工作流
- javascript - 使用javascript从字符串中删除时间
- node.js - 没有安装npm?
- python - 当使用预测作为训练示例时,为什么我的损失函数不为零?
- python - 获取输出不断变化的子进程的输出
- python - 如何在模型的 CharField 中查询对象的子值?
- javascript - Javascript - 检查是否为空的 if 语句不起作用
- css - Flexbox 难题 - 如何将 flex box 嵌套在自定义元素的层中并通过媒体查询获得所需的结果