2024-03-19 01:02 AM - edited 2024-03-19 01:05 AM
CubeIDE doesn't look for C++ files. Even worst, no matter that the main.c file has been marked for being excluded from the building, the tool always uses it.
Although I started the project as a C++ one, the tool didn't generate the corresponding main.cpp file, so I did it by hand.
Even worst (yes, things can get ugly pretty quickly) the IOC tool removes silently the "don't compile the main.c file because it's a C++ project" flag.
What can I do?
From the image below please note that the main.c file has been excluded but the compiler (right pane) is compiling it anyway. Also note that the file main.cpp isn't compiled. The functions MainApp() and Tick_IRQUserCallback() are located inside this file:
Solved! Go to Solution.
2024-03-19 09:10 PM
SOLVED!
Classic name mangling problems plus IOC doesn't like main.cpp files.
1. I avoided to have two main files; I renamed the main file for the C++ project's logic as MainApp[.cpp, .hpp]
2. I had my __cplusplus guards misplaced, so I reworked them as:
MainApp.hpp
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void MainApp();
#ifdef __cplusplus
}
#endif
MainApp.cpp
#include "MainApp.hpp"
void MainApp()
{
while (1)
{
heartbeat_led.on();
HAL_Delay( 500 );
heartbeat_led.off();
HAL_Delay( 500 );
}
}
main.c
#include "MainApp.hpp"
int main()
{
// ...
MainApp();
while( 1 )
;
}
Thank you all for your suggestions and hints; those led me to the solution :)
2024-03-19 05:57 AM
CubeMX is set up to generate main.c. There is no changing that. C++ projects can have C files in them, it is typically unavoidable.
Right click your project and convert it to C++.
Ensure the Tool Settings tab shows a C++ compiler step.
Exclude from Build is configuration-specific. Ensure it's marked for the configuration you're building.
Would be good to see more of the output here. You've cropped out configuration names and project names and the start of the output panel. It might be compiling something unexpected.
2024-03-19 01:23 PM
Hi!
"CubeMX is set up to generate main.c. There is no changing that. C++ projects can have C files in them, it is typically unavoidable."
I understand that, however having two main files is why I don't get it.
"Right click your project and convert it to C++.
Ensure the Tool Settings tab shows a C++ compiler step."
The project already includes the C++ compiler step, but it refuses somehow to compile my .cpp files:
"Exclude from Build is configuration-specific. Ensure it's marked for the configuration you're building."
I've excluded main.c from all my configurations, yet it gets compiled:
"You've cropped out configuration names and project names and the start of the output panel. It might be compiling something unexpected."
Sorry for that. I'm not allowed to reveal the project I'm working on. However, the path for both .c and .cpp files are the same, as you saw in the images.
In fact, all my projects are C++, but this the first time with this tool that I'm facing this problem. I have no time to start the project from scratch, that's way I'm looking for a solution over this same project.
My workaround is that main.c, besides initialization, calls my MainApp() function (inside main.cpp) in which I'll develop my logic (plus a tons of other C++ files that will be called later). But as you've seen it's not working.
Thank you and more hints will be welcomed!
2024-03-19 03:13 PM - edited 2024-03-19 03:15 PM
>The project already includes the C++ compiler step
Please do as advised by TDK: "Right click your project and convert it to C++.
> having two main files is why I don't get it.
The main file is where the main() function is. There should be only one file with base name "main", because of Eclipse CDT build system. So there should be no main.cpp.
Right click on the project in the project manager view in Eclipse, click Refresh (F5). Now you are all set.
2024-03-19 09:10 PM
SOLVED!
Classic name mangling problems plus IOC doesn't like main.cpp files.
1. I avoided to have two main files; I renamed the main file for the C++ project's logic as MainApp[.cpp, .hpp]
2. I had my __cplusplus guards misplaced, so I reworked them as:
MainApp.hpp
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
void MainApp();
#ifdef __cplusplus
}
#endif
MainApp.cpp
#include "MainApp.hpp"
void MainApp()
{
while (1)
{
heartbeat_led.on();
HAL_Delay( 500 );
heartbeat_led.off();
HAL_Delay( 500 );
}
}
main.c
#include "MainApp.hpp"
int main()
{
// ...
MainApp();
while( 1 )
;
}
Thank you all for your suggestions and hints; those led me to the solution :)