cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing my library

MexiAxel
Associate II

Hello, I am having problems adding my library to my project. I added the .h file to Core/Inc and my .c file to Core/Src. I included the .h in Model.cpp since that is where I want to use it. I can use the definitions that are in my header file but not the functions. I think it is not able to properly link with the .c file and I do not know how to fix it.

C:/TouchGFXProjects/test/TouchGFX/gui/src/model/Model.cpp:46: undefined reference to `i2c_master_write(unsigned char*, unsigned long)'

6 REPLIES 6
STea
ST Employee

Hello @MexiAxel ,

I suggest you try the following:

  1. open project properties 
  2. Add files to that project Include paths ( project->properties->c/c++ General->path and symbols ->includes ) (IN which folder files are available)
  3. Add folder (project->properties->c/c++ General->path and symbols -> Source Location ) (select your source folder)

if you are still having issues feel free to share it hope you find this helpful.

BR Hichem.

In order 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.

Sounds like you haven't added the source file to the project.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
KnarfB
Principal III

Calling a C function from C++ code requires the function to have extern "C" linkage, see https://en.cppreference.com/w/cpp/language/language_linkage and HAL header files.

hth

KnarfB

I tried this and it didn't work so I deleted the paths that I created but it caused other issues.

C:/TouchGFXProjects/test/STM32CubeIDE/Debug/../Application/Startup/startup_stm32f429zitx.s:113: undefined reference to `main'

I tried making a new project, but for some reason now I can not build any of my projects. If I press the build button it builds way too fast and it doesn't actually build anymore, it doesn't even tell me the errors either.

I did

 

you need to add the extern "c" before you include your header i have tested it and it works fine this is illustrated in the picture bellow you can check this link for more details about mixing c and c++ you will also find a screenshot of the template project  with extern "c" addition 

STea_0-1699030989645.png

the main.cpp

STea_1-1699031538049.png

example.h

STea_3-1699031618565.png

example.c

STea_4-1699031638916.png

 

STea_2-1699031565771.png

 

 

 

BR

In order 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.