cancel
Showing results for 
Search instead for 
Did you mean: 

How to link library (.c and .h file) in CubeIDE?

HPham.1590
Senior

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

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

14 REPLIES 14
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".
prain
Senior III

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.​

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();
}

but I dont know how to link these file. My function define in .h but written in .c file

Not sure what you mean. Your .h file doesn't have any code, just definitions. The processor can't jump there.

If you feel a post has answered your question, please click "Accept as Solution".

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?

dbgarasiya
Senior II

just follow given instructions

Sorry, that's my example file. In case file with fully code, it still not linking

HPham.1590
Senior

Well, that's my mistake. It's still linking but I tried to call this C lib in C++ file.

Sorry,

Hieu