I have a small issue.
I thought that using using extern "C"
will turn the C code into C++ code directly.
#ifdef __cplusplus
extern "C" {
#endif
ENUM_J1939_STATUS_CODES CAN_Send_Message(uint32_t ID, uint8_t data[], uint8_t delay);
ENUM_J1939_STATUS_CODES CAN_Send_Request(uint32_t ID, uint8_t PGN[], uint8_t delay);
bool CAN_Read_Message(uint32_t *ID, uint8_t data[]);
#ifdef __cplusplus
}
#endif
But when I placed a class QSerialPort
in here
#ifdef __cplusplus
extern "C" {
#endif
#include <QSerialPort>
ENUM_J1939_STATUS_CODES CAN_Send_Message(uint32_t ID, uint8_t data[], uint8_t delay);
ENUM_J1939_STATUS_CODES CAN_Send_Request(uint32_t ID, uint8_t PGN[], uint8_t delay);
bool CAN_Read_Message(uint32_t *ID, uint8_t data[]);
#ifdef __cplusplus
}
#endif
Then I got 500 errors about data types, name space and all kind of C++ keywords that C does not have.
Question:
In QT. I have to make sure that I can use a C++ class inside a .h
file and the .h
is included inside a .c
file. But right now, my QT IDE shows me 500 errors if I do that.
Is there a way for C code to call C++ code or turning the C code into 100% C++ code, whithout renaming the files .c
to .cpp
?
My goal is to use C++ features from C, by using extern "C"
inside the header of the .c
file, but it isin't going any well for me.
Edit:
I tried some ways and this does not work. I get 500 errors.
#include <QSerialPort>
#ifdef __cplusplus
extern "C" {
#endif
void QT_USB_set_serial_handler(QSerialPort* serial_port);
ENUM_J1939_STATUS_CODES QT_USB_Transmit(uint32_t ID, uint8_t data[], uint8_t DLC);
void QT_USB_Get_ID_Data(uint32_t *ID, uint8_t data[], bool* is_new_message);
#ifdef __cplusplus
}
This gives only one error.
#ifdef __cplusplus
#include <QSerialPort>
extern "C" {
#endif
void QT_USB_set_serial_handler(QSerialPort* serial_port); <-- complaining here on QSerialPort keyword
ENUM_J1939_STATUS_CODES QT_USB_Transmit(uint32_t ID, uint8_t data[], uint8_t DLC);
void QT_USB_Get_ID_Data(uint32_t *ID, uint8_t data[], bool* is_new_message);
#ifdef __cplusplus
}
This gives no error at all.
#ifdef __cplusplus
#include <QSerialPort>
void QT_USB_set_serial_handler(QSerialPort* serial_port);
extern "C" {
#endif
ENUM_J1939_STATUS_CODES QT_USB_Transmit(uint32_t ID, uint8_t data[], uint8_t DLC);
void QT_USB_Get_ID_Data(uint32_t *ID, uint8_t data[], bool* is_new_message);
#ifdef __cplusplus
}