cancel
Showing results for 
Search instead for 
Did you mean: 

Excluding files from build not working

aroni525
Associate II

Hi,

since I have upgraded to 1.7.0 a few of my C++ projects stopped working. When I code in C++ I always create main.cpp file and I exclude from all builds main.c file (I don't delete this file as it is always generated by CubeMX). This has been working for a long time.

But now it crashes. It still try to compile main.c file. What's more, if I delete main.c file, linker tells me that it cannot find main symbol. For some reason compiler doesn't compile my main.cpp file. I have C++ nature set up and all other .cpp files are compiled, but not the main.cpp...

Everything was working until I upgraded to a new STM32CubeIDE version. I check on 3 computers, everywhere it stopped working.

Is there any know bug related to this problem?

Best,

Arek

17 REPLIES 17
TDK
Guru

The entire IDE crashes/exits if you try to compile a project with a main.cpp file?

Show the error messages being output as well as the full compiler/linker commands.

Show that you have a C++ compiler set up in project options and that the path to main.cpp is in the source locations and it isn't being excluded.

If you feel a post has answered your question, please click "Accept as Solution".
aroni525
Associate II

No, IDE doesn't crashes, but the compilation process fails.

Maybe more descriptively:

When I start a C++ project for research purposes I always use HAL libraries and project structure generated by STM32CubeMX. By default a file main.c is created with necessary initialization code.

I always create my own main.cpp file and copy necessary code from main.c, and I add my custom code to call some objects and do the job. At this stage I have two main files and two definitions of main(). In order to get rid of multiple definitions I always enable "Exclude from build" options for original main.c file (I leave all its content).

I do the same with a few other automaticaly generated files, but for a sake of simplicity lets focus on a main file and main() function.

For all previous STM32CubeIDE versions it works as expected - g++ compiles main.cpp file with main() function and the compiler ignores main.c file with all its content.

When I updated my IDE to 1.7.0 it stopped working. During the compilation of the same project it suddenly says that I have multiple definitions of some functions (Error_Handler(), assert_failed()). I always copy those functions from main.c to other custom files. This means that for some reason compile ignores option "Exclude from build" and still tries to compile main.c. Whats more, it doesn't "see" the main.cpp file, so when I comment out all code from main.c it crashes, because there is no main symbol.

All in all, compiler compiles files that shouldn't be compiled (marked as "Exclude from build") and skips some files that should be compiled. Sure, I could rebuild the entire project from scratch or delete problematic files, but I do expect from the IDE not to break my projects and work out of the box. It was working for a long time until 1.7.0 release.

I went back to 1.6.1 and the project started working again as it was. So I will wait for a new release. But maybe this is some kind of bug, that is why I posted this.

Best,

Arek

Have you created a new workspace for 1.7 and imported the project into it?

Can you reproduce the problem on a new clean workspace and new project ?

TDK
Guru

> When I updated my IDE to 1.7.0 it stopped working. During the compilation of the same project it suddenly says that I have multiple definitions of some functions (Error_Handler(), assert_failed()). I always copy those functions from main.c to other custom files. This means that for some reason compile ignores option "Exclude from build" and still tries to compile main.c. Whats more, it doesn't "see" the main.cpp file, so when I comment out all code from main.c it crashes, because there is no main symbol.

Things aren't really adding up here. If you have duplicate symbols reported by the linker, it's including both main.c and main.cpp. So why wouldn't it see the main() in main.cpp it if sees the other symbols in there?

Exclude from build is build configuration specific. Ensure the active config is the one you're actually building. Should show up grayed out in the Project Explorer.

If you feel a post has answered your question, please click "Accept as Solution".

Yes, I have created new clear workspace for 1.7 and imported project into it as it was working in 1.6. I will try to reproduce it later when I get back to home.

aroni525
Associate II

Ok, maybe I didn't wrote it clearly enough.

When I mentioned duplicated symbols I meant i.e. functions like Error_Handler(), assert_failed(). These functions originally exists in the main.c file. I copy them to the, lets say, setup.cpp file. Then I copy the main() function to the main.cpp file.

I exclude from the build file main.c as I don't need it. Remaining two files main.cpp (with main() function) and setup.cpp (with other functions) contains all necessary definitions.

During the compilation I can still see gcc compiling main.c file, g++ compiling setup.cpp file (here are duplicated symbols) and the main.cpp file is ignored.

My active config is always set to debug. The icon is crossed, but not grayed in the Project Explorer. Now the question why...

0693W00000DmQNsQAN.png

JensH
Associate III

Hi Arek,

sorry but I can't really help you, but I have exactly the same problem. My workflow is nearly the same as yours.

I do these steps:

  • creating a new "STM32 project" in STM32CubeIDE
  • selecting Processor or Board
  • Selecting "C++" as Target Language
  • At the Project Manager I select "Generate peripheral initialization as a pair of '.c/.h' files per peripheral"
  • Now I copy the whole main.c to main.cpp
  • eclude main.c from all builds
  • in the main.cpp there are some changes needed:
    • /* Private function prototypes -----------------------------------------------*/ extern "C" void SystemClock_Config(void);
    • and extern "C" {} for everything after the "int main(void) {}"

With the older versions of the CubeIDE everything worked well. But now the build is made with main.c which is ecluded, instead of the main.cpp.

If I rename the main.cpp to main+.cpp for example it is working. I hope my explanation will additionally help to find the problem.

I have also tried to find an answer at the Eclipse or GNU communities, but I didn't find anything. My ST-Support ticket is unfortunately still open.

Best regards,

Jens

PKesk.1
Associate II

Hi!

I'm now having the same problem. Did someone already find a solution?

Try to clean the project, them delete the main.c (move to other place) and refresh the project. Will it build then?