cancel
Showing results for 
Search instead for 
Did you mean: 

Add new C file to my STM32 project in VS Code

fritz3917
Associate

If I add a new .c file to my project in core/src it does not get recognized and is not complled. How do I get it into the make list?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Julien D
ST Employee

Hi @fritz3917,

There is no managed build, so you must define your new source file manually, preferably by editing the top-level CMakeLists.txt file:

# Add sources to executable/library
target_sources(<PROJECT_NAME> PRIVATE
  # User defined sources
  core/src/newFile.c
)

 <PROJECT_NAME> to be replaced according to your project (see used value from the cmake files).

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

4 REPLIES 4
Julien D
ST Employee

Hi @fritz3917,

There is no managed build, so you must define your new source file manually, preferably by editing the top-level CMakeLists.txt file:

# Add sources to executable/library
target_sources(<PROJECT_NAME> PRIVATE
  # User defined sources
  core/src/newFile.c
)

 <PROJECT_NAME> to be replaced according to your project (see used value from the cmake files).

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Thanks, that worked.

@Julien D wrote:

There is no managed build


Seems like a retrograde step from CubeIDE ?

Will you be adding that (or equivalent) in the future ?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.


Seems like a retrograde step from CubeIDE ?


It depends on what you are looking for. A CubeIDE Eclipse/CDT project is primarily designed to be managed within that IDE, with the build and project configuration driven by the IDE’s project model. This makes it easy to support features such as managed build.

A CMake project, on the other hand, is intended to be more IDE-agnostic and is generally easier to integrate into a CI/CD environment. That said, I admit that CMake’s learning curve can make it seem more complicated at first.

For some developers, managed build is an advantage; for others, it is a drawback. In the end, it is a tradeoff between explicit control and IDE-managed convenience.

 


Will you be adding that (or equivalent) in the future ?


Having additional facilities on top of CMake is something we are considering.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.