2021-05-27 03:13 AM
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 =)
2021-05-27 04:01 AM
OK, found it. For someone else struggling with the craziness of this:
You have to go to Project Properties and add the folder just like you do with the include paths. Obv. :see_no_evil_monkey:
2021-05-27 04:49 AM
Wishlist: A way to add only select source files from some folders, where the bulk of the files you don't need.
2021-05-27 04:50 AM
You can do this by drag&drop feature. In file browser select files and drop them to source folder in CubeIDE project.
2021-05-27 05:10 AM
Thank you Tilen
2022-09-07 11:13 AM
Drag&drop doesn't seem to work for all folders :(
My project has directories that are shared between the two projects for two CPU cores of the MCU, and the shared directories are outside the two project directory structures. Neither drag&drop nor Refresh seem to work there, specifically the the bottom-level directories (drag&drop seems to work for higher-level shared directories, but Refresh doesn't pick up the new .c files).
2022-09-26 03:10 PM
Still don't see how you did it. In Project > Properties, I can see how to add an include file or path, but not a C++ file or path. How did you do it? I, on the other hand, am new to STM32Cube
2023-05-02 05:43 AM
I followed your solution and it still reports an `undefined reference to function`. In Core, I've created a Cpp folder, added my header file with an extern void declaration, and a source file with the void definition. I've obviously included the header file in the source file, and in the main.c file, but calling the void from the main function still gives an undefined reference function. Using 1.12.1 version.
2023-05-02 08:38 AM
Hello @MConi.1 and welcome to the community,
It would be better to post this issue using CubeIDE version 1.12.1 in a new community thread.
Basically you can place source file in any source folder. You can use existing folders or create a new one.
Header files have to be placed inside an include folder that is in the include path (e.g.
Core/Inc) or you have to tell the compiler that a specific file should be included. If you want to create a new folder for your header files you have to add the folder or files inside this folder to the include path via:
Project -> Properties -> C/C++ Build -> Tool Setting (tab) -> MCU GCC Compiler or MCU G++ Compiler -> Include paths
Thanks,
Rim
2023-05-02 10:16 AM
Please note also that you must have blue C mark on the C source folder, otherwise source files are not found/compiled. You can change your folder include/exclude -property by select folder -> right click -> properties -> C/C++ build -> Exclude resource from build