Qt当我尝试包括头文件时,没有这样的文件或词典
这是Qt中非常常见的问题。包括头文件,然后出现错误。
No such file or directory
如何重现问题:
首先我使用的是CAN Bus Open SAE J1939库
然后,我像这样包括源和标头。
SOURCES += Communication/Database/databasehandling.cpp Tool/Json/jsonhandling.cpp main.cpp Window/Main/mainwindow.cpp Communication/USB/usb.cpp Tool/CAN/Hardware/CAN_Network/CAN_Network.c Tool/CAN/Hardware/Memory/FLASH_EEPROM_RAM_Memory.c Tool/CAN/ISO_11783/ISO_11783-7_Application_Layer/Auxiliary_Valve_Command.c Tool/CAN/ISO_11783/ISO_11783-7_Application_Layer/Auxiliary_Valve_Estimated_Flow.c Tool/CAN/ISO_11783/ISO_11783-7_Application_Layer/Auxiliary_Valve_Measured_Position.c Tool/CAN/ISO_11783/ISO_11783-7_Application_Layer/General_Purpose_Valve_Command.c Tool/CAN/ISO_11783/ISO_11783-7_Application_Layer/General_Purpose_Valve_Estimated_Flow.c Tool/CAN/Open_SAE_J1939/Listen_For_Messages.c Tool/CAN/SAE_J1939/SAE_J1939-21_Transport_Layer/Acknowledgement.c Tool/CAN/SAE_J1939/SAE_J1939-21_Transport_Layer/Request.c Tool/CAN/SAE_J1939/SAE_J1939-21_Transport_Layer/Transport_Protocol_Connection_Management.c Tool/CAN/SAE_J1939/SAE_J1939-21_Transport_Layer/Transport_Protocol_Data_Transfer.c Tool/CAN/SAE_J1939/SAE_J1939-71_Application_Layer/Request_Component_Identification.c Tool/CAN/SAE_J1939/SAE_J1939-71_Application_Layer/Request_ECU_Identification.c Tool/CAN/SAE_J1939/SAE_J1939-71_Application_Layer/Request_Software_Identification.c Tool/CAN/SAE_J1939/SAE_J1939-73_Diagnostics_Layer/DM1.c Tool/CAN/SAE_J1939/SAE_J1939-73_Diagnostics_Layer/DM2.c Tool/CAN/SAE_J1939/SAE_J1939-73_Diagnostics_Layer/DM3.c Tool/CAN/SAE_J1939/SAE_J1939-73_Diagnostics_Layer/DM14.c Tool/CAN/SAE_J1939/SAE_J1939-73_Diagnostics_Layer/DM15.c Tool/CAN/SAE_J1939/SAE_J1939-73_Diagnostics_Layer/DM16.c Tool/CAN/SAE_J1939/SAE_J1939-81_Network_Management_Layer/Address_Claimed.c Tool/CAN/SAE_J1939/SAE_J1939-81_Network_Management_Layer/Address_Delete.c Tool/CAN/SAE_J1939/SAE_J1939-81_Network_Management_Layer/Address_Not_Claimed.c Tool/CAN/SAE_J1939/SAE_J1939-81_Network_Management_Layer/Commanded_Address.c HEADERS += Communication/Database/databasehandling.h Tool/Json/jsonhandling.h Window/Main/mainwindow.h Communication/USB/usb.h Tool/CAN/Hardware/CAN_Network/CAN_Network.h Tool/CAN/Hardware/Memory/FLASH_EEPROM_RAM_Memory.h Tool/CAN/Hardware/Processor_choice.h Tool/CAN/ISO_11783/ISO_11783_Enums/Enum_Auxiliary_And_General_Purpose_Valves.h Tool/CAN/ISO_11783/ISO_11783-7_Application_Layer/Application_Layer.h Tool/CAN/Open_SAE_J1939/Open_SAE_J1939.h Tool/CAN/Open_SAE_J1939/Structs.h Tool/CAN/SAE_J1939/SAE_J1939_Enums/Enum_Control_Byte.h Tool/CAN/SAE_J1939/SAE_J1939_Enums/Enum_DM1_DM2.h Tool/CAN/SAE_J1939/SAE_J1939_Enums/Enum_DM14_DM15.h Tool/CAN/SAE_J1939/SAE_J1939_Enums/Enum_Group_Function_Value.h Tool/CAN/SAE_J1939/SAE_J1939_Enums/Enum_NAME.h Tool/CAN/SAE_J1939/SAE_J1939_Enums/Enum_PGN.h Tool/CAN/SAE_J1939/SAE_J1939_Enums/Enum_Send_Status.h Tool/CAN/SAE_J1939/SAE_J1939-21_Transport_Layer/Transport_Layer.h Tool/CAN/SAE_J1939/SAE_J1939-71_Application_Layer/Application_Layer.h Tool/CAN/SAE_J1939/SAE_J1939-73_Diagnostics_Layer/Diagnostics_Layer.h Tool/CAN/SAE_J1939/SAE_J1939-81_Network_Management_Layer/Network_Management_Layer.h
但我在Transport_Layer.h
文件中仍收到一个错误
#ifndef SAE_J1939_21_TRANSPORT_LAYER_SAE_J1939_21_TRANSPORT_LAYER_H_
#define SAE_J1939_21_TRANSPORT_LAYER_SAE_J1939_21_TRANSPORT_LAYER_H_
/* Layers */
#include "../../Hardware/CAN_Network/CAN_Network.h"
#include "../../Open_SAE_J1939/Structs.h"
#include "../SAE_J1939-71_Application_Layer/Application_Layer.h"
#include "../SAE_J1939-73_Diagnostics_Layer/Diagnostics_Layer.h"
#include "../SAE_J1939-81_Network_Management_Layer/Network_Management_Layer.h" <--- This one
#include "../SAE_J1939_Enums/Enum_Control_Byte.h"
#include "../SAE_J1939_Enums/Enum_DM1_DM2.h"
#include "../SAE_J1939_Enums/Enum_DM14_DM15.h"
#include "../SAE_J1939_Enums/Enum_Group_Function_Value.h"
#include "../SAE_J1939_Enums/Enum_NAME.h"
#include "../SAE_J1939_Enums/Enum_PGN.h"
#include "../SAE_J1939_Enums/Enum_Send_Status.h"
和一个在Application_Layer.h
文件中
#ifndef ISO_11783_ISO_11783_7_APPLICATION_LAYER_ISO_11783_7_APPLICATION_LAYER_H_
#define ISO_11783_ISO_11783_7_APPLICATION_LAYER_ISO_11783_7_APPLICATION_LAYER_H_
/* Layers */
#include "../../Hardware/CAN_Network/CAN_Network.h"
#include "../../ISO_11783/ISO_11783_Enums/Enum_Auxiliary_And_General_Purpose_Valves.h" <-- This one
#include "../../Open_SAE_J1939/Structs.h"
#include "../../SAE_J1939/SAE_J1939-21_Transport_Layer/Transport_Layer.h"
#include "../../SAE_J1939/SAE_J1939_Enums/Enum_PGN.h"
问题:
为什么会发生这种情况? 我已经包括在内了。Qt Creator IDE会看到这些文件。这没什么问题。但是,编译器似乎不理解这些文件的存在。
我使用的是Qt 5.15.2和C++11。
解决方案
我找到了适合我的解决方案。您不需要.pri
文件,如此处的答案所示。扔掉它。
以下是我所做的。
- 在Qt中右击您的项目。
- 选择添加现有词典(&Q)
- 标记要导入的词典。现在,您可以在
.pro
文件中看到许多.c
和.h
文件。
提示:不要使用../../
,这可能会带来麻烦。改为使用项目路径,例如
"ThirdLibrary/OpenSAEJ1939/...your_h_files.h"
完成!
相关文章