How to exclude *cpp file from compilation

I am writing code for one project, in which, in addition to *ino, in one folder there are files *cpp and *h
The folder name and the sketch name are the same.
I need to temporarily exclude files from compilation, i.e. let's say now you need to compile one file *ino, but because now in the folder there is also a *cpp file, then the compiler, of course, gives an error, because so far I have not written the code correctly in the *cpp file.
The compiler gathers together all *cpp and *ino files in one folder.
If I physically delete the *cpp file, then the compilation of the sketch *ino goes without errors, but this method of "physical deletion" is not technologically advanced, and I constantly have to restore the deleted file from the trash.
I am using the arduino-cli command line to compile the sketch and upload it to the board.
Used the GPT chat for hints and help and tried to use the --exclude flag, but this flag is not supported on the command line.
I also tried to add an exception to the library.properties file and put the file in the folder with my sketch.

name=Bla bla bla
version=0.1
author=myName
includes=*
exclude=notNeededFile.cpp

But this method also did not bring the desired result.
Can you please tell me a simple way, besides deleting files, to compile the sketch and temporarily exclude unnecessary files?

As far I know, there is no such way besides deleting, the Arduino always compiles all source files in project folder

1 Like

Any compiler should be able to customize the assembly.
Deleting files is certainly good and solves the problem, but not exactly what I would like to put into practice.

It compiler do it, arduino ide don't

1 Like

That's right, the compiler, I didn't put it that way.
But arduino cli does not have the ability to configure the inclusion and exclusion of files in the assembly when compiling the project?

I don't think it is productive to throw made up flags at Arduino CLI in hopes you might happen to stumble on the the wished for capabilities. You can learn all the supported flags by adding the help flag to a command.

I have the same opinion here. Adding made up fields to the file is not productive. You can learn all the supported fields from the Arduino Library Specification:

https://arduino.github.io/arduino-cli/latest/library-specification/#library-metadata

The most simple way is to comment out or disable all the non-functional code in the .cpp file. You can use a multi-line comment:

/*
non-functional code here
[...]
*/

Using multi-line comments to disable code can be problematic in cases where the code contains multi-line comments. You can use a preprocessor conditional that evaluates to false instead:

#if false  // Disable unfinished code
non-functional code here
[...]
#endif

the question is why do you have those files there in the first place? if they are not needed and sketch.ino compiles fine without anything else, what's their use?

Temporarily change the .cpp extension to something else.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.