PlatformIO Community

Compile single source

When working on a large project, even a small typo in a header file can generator massive error messages and the actual error message can get hidden in the sea of aborted compiles.

Is there a way to tell the core or the ide to compile only once source; in orders words one .o?
This would be very helpful in isolating issues that actually affect multiple sources.

It’s possible but it’s rather cumbersome:

Run the compile command manually from a terminal.

In order to find the correct command, run the entire build from the terminal with:

pio run -v

Then search the log for the file that you would like to compile and copy the entire command. Depending on the framework used, it can be quite a long command.

But generally the synatx highlighting (IntelliSense and the like) you warn you early about errors. And if the error only occurs during compilation, go through the log and strictly work top to bottom. That way it’s much easier to spot that an error is just a repeating or subsequent error.

1 Like

I totally agree with Greg that it should be possible to select a single file to compile.

Another solution is to use the -t option
If you run the “pio run” command, then you can identify the target object file you would like to compile.
e.g. if you have the main.cpp within the src folder and you run the “pio run” command, then you shoud see something like the following

Compiling .pio\build\lolin_d32\src\main.cpp.o

So if you just want to build the main.cpp file, you can invoke pio as follows:
pio run -t .pio\build\lolin_d32\src\main.cpp.o

In that way, you can refactor your code in a more professional and also faster way :slight_smile: