2020-08-12 04:56 AM
Hello, I'm new in STM32CubeIDE.
I want to create my library to use in my C/C++ project.
My library includes 2 files (.c and .h) but I don't know how to linking them in CubeIDE.
Anyone can help me?
Many thanks,
Hieu
Solved! Go to Solution.
2020-08-12 05:40 AM
Drag them into the Core/Src and Core/Inc (or Src and Inc) folders within your project. Add an #include statement for the header and use them in whatever file you need.
2020-08-12 05:40 AM
Drag them into the Core/Src and Core/Inc (or Src and Inc) folders within your project. Add an #include statement for the header and use them in whatever file you need.
2020-08-12 07:56 AM
In cubeide you don't need to register source files for compiler. There are directories under project root, named source folders, that you can put compilable files into. just copy paste your files in a source directory and you are good to go. you can later exclude files from compile through project options.
2020-08-12 08:58 PM
Thanks for your reply, but when i using CubeIDE, I added these file to locations as your refer but when I call function in this lib from other file, it still jump to .h file, not .c file.
Here is my simple .h file
#ifndef __GETCONFIG_H__
#define __GETCONFIG_H__
void SimJSON();
void GetConfig();
#endif
and .c file
#include "GetConfig.h"
#include "cJSON.h"
void SimJSON()
{
}
void GetCongif()
{
SimJSON();
}
2020-08-12 08:59 PM
but I dont know how to link these file. My function define in .h but written in .c file
2020-08-13 05:56 AM
Not sure what you mean. Your .h file doesn't have any code, just definitions. The processor can't jump there.
2020-08-13 06:11 AM
A .h plus .c file is just source code, not a library that needs extra consideration for linking. If you follow the above instructions, you should see the .c file being compiled in the CDT Console Window.
Are you getting errors? What exactly?
2020-08-13 08:47 PM
2020-08-14 03:36 AM
Sorry, that's my example file. In case file with fully code, it still not linking
2020-08-14 03:39 AM
Well, that's my mistake. It's still linking but I tried to call this C lib in C++ file.
Sorry,
Hieu