2019-05-27 02:00 AM
1. How to configure the IDE to use g++ compiler to compile all the files includes "*.c" files in the project?
Current it compiles the .c files by using gcc and .cpp by using g++ ...
2. If I rename main.c to main.cpp, the cube code generator will create a new main.c file instead of using main.cpp. Any sulotions for this?
Becasue main.c is .c file, so the IDE use gcc to compile this file, and this caused that I can't use any objects in it. But if I changed the main.c to main.cpp, the cube can't generate code into it...:face_screaming_in_fear:
2021-11-03 11:39 PM
I've just been renaming main.cpp back to main.c any time I want to change the ioc. I rename back to main.c, let it generate it's code, then rename back to .cpp so things compile properly.
It's a bit of a pain, but it's what works for me.
2021-11-04 08:24 AM
I have forgotten to rename the .cpp to .c every now and then. Using the idea of a linking program lets you keep the .c file, and no renaming is needed. I opted for a permanent solution rather than "remember to do this each time."
2022-08-14 12:25 PM
Il est possible de renommer le fichier main.c en main.cpp et de convertir ensuite le projet en C++.
Ensuite, il faut prendre le soin d'ajouter extern "C" juste après l'insertion des directives de préprocesseur #include afin de prendre en compte le langage C dans le fichier main.cpp
Le compilateur gcc compilera les fichiers d'extension .c et g++ compilera séparément les fichiers d'extension .cpp
J'espère que ce post résoudra le problème de nombre de programmeurs.
Cordiales salutations,
Dom
2022-08-14 12:35 PM
2022-08-16 07:48 AM
Sorry for this necromancy, but this is simple problem I think.
A.h must be understandable for both C and C++ compilers.
In example below, Serial.h is C++ header with some classes and so on. A.h is included in main.c and both setup() and loop() functions are called in main.c.
A.h:
#ifndef INC_A_H_
#define INC_A_H_
// C INCLUDES
#include "main.h"
#ifdef __cplusplus
extern "C" {
// CPP INCLUDES
#include "Serial.h"
#endif
// DECLARATIONS
void setup();
void loop();
#ifdef __cplusplus
}
#endif
#endif /* INC_A_H_ */
A.cpp:
#include "A.h"
class CustomType {
};
void setup() {
}
void loop() {
}
2024-02-10 09:12 PM
I should point out an error that the code somewhat obscured.
CPP_LINK sets things up and then returns, so the main user loop does run. The delay of 10000 clock ticks says that it will run, delay for 10 seconds, then run again. If you wanted to put something there, it would work. Structurally, however, I generally don't.