记录备忘
1.报错信息
In file included from /home/zxq/CLionProjects/test_my_inference_onnx/include/detector.cpp:9:0:
/home/zxq/CLionProjects/test_my_inference_onnx/include/detector.h:14:7: error: redefinition of ‘class Detector’
class Detector {
^~~~~~~~
In file included from /home/zxq/CLionProjects/test_my_inference_onnx/include/detector.cpp:5:0:
/home/zxq/CLionProjects/test_my_inference_onnx/include/detector.h:14:7: note: previous definition of ‘class Detector’
class Detector {
简单的说就是class Detector重复定义了。
2.报错原因
同一个文件内#incude两次detect.h.
#include "detector.h"
编译时,include两次,这就导致重复定义了。
3.解决办法
#ifndef TEST_MY_INFERENCE_ONNX_DETECTOR_H
#define TEST_MY_INFERENCE_ONNX_DETECTOR_H
// 在这里面定义函数
#endif //TEST_MY_INFERENCE_ONNX_DETECTOR_H
所以以后定义新的头文件都要定义一个独一无二的宏,包起来,保险点。