cancel
Showing results for 
Search instead for 
Did you mean: 

How to add C source files to a project in a Cube IDE project

DiBosco
Senior

I'm no noob to the STM32, but I am to Cube IDE.

I've added a new directory for my user code to separate it as much as possible from this dog's dinner of code that Cube auto config creates.

I've created a new function, it's all correct, its prototype is in its header file, yet the compiler is telling me that there's an undefined reference to the function I'm trying to call from the Cube generated code.

The code is right, so there must be something wrong with the way I've created the new files and that the IDE hasn't automatically added them to the project.

Include directories are set up in the project. If I control click on the function the compiler is complaining about not seeing, the IDE takes me to the function.

I just created a new directory in Eclipse, then created new files by right clicking on the new directory and selecting file from template, then wrote my code. Is there a non-obvious step you have to take to somehow add the actual file to the project? You'd expect the IDE just to add it to the project, but then this is Eclipse and anything's possible with Eclipse.

Thanks =)

14 REPLIES 14

Thank you, @JTP1 . Learning how to change the folder include/exclude property was very helpful. I was getting pretty tired of reading the CubeIDE manual to figure out how to do this.

even if I added the folder , it still prompt " undefined reference to `delay_ms'" ( this delay_ms() function is defined in delay.h file , I have added to the project include path.

Not worked. " undefined reference to `delay_ms'" ( this delay_ms() function is defined in delay.h file , I have added to the project include path.

KBéla.1
Associate III

Create Source Folder for filesystem where source files are available, instead of simple folder. See attachement.

Right click on project - New - Source Folder

And now the compiler can find the source files in Source Folder

RebelEngineer
Associate II

I've been struggling with setting up a USB audio device for the past week or so.. A few hours ago I found a reference to document UM1734 about working with the USB device library. I followed the instructions from paragraph 6.4.3, how to use the USB Audio class driver. It specifies to put a call to USBD_AUDIO_Init() in the setup. I did that but it turned out the library files were not even added to my project after setting up the device and generating code. (After selecting USB_OTG_FS under Connectivity and USB_Device_M7 under Middleware and setting it up to use the audio device class).

So I looked up which files I need to add and added them to my Src and Inc folders, but it turns out the USBD_AUDIO_Init() function was not even defined in the header file. So I added it, but when building, I keep getting the same error.

I looked at all the previous suggestions in this thread but none of them helped with this issue.. Building the code still reports an undefined reference to USBD_AUDIO_Init(), which is clearly not undefined as you can see in the screenshot. The files and folders are not excluded from build and as you can see in the build log, building them works fine. I see in the file explorer that the object file exists and it's listed in the subdir.mk file as well.

It would be really nice if I could just find some instructions that actually work without an advanced course in USB protocols and such. All I wanted to do was test I2S input data from an ADC chip on a custom H503 board, but it seems it's far from trivial to even get this to work on a nucleo H755 (haven't tried any other Nucleo or Disco boards yet)..