2023-11-03 02:15 AM
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)'
2023-11-03 03:54 AM
Hello @MexiAxel ,
I suggest you try the following:
if you are still having issues feel free to share it hope you find this helpful.
BR Hichem.
2023-11-03 05:09 AM
Sounds like you haven't added the source file to the project.
2023-11-03 05:27 AM
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
2023-11-03 07:43 AM - edited 2023-11-03 07:45 AM
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.
2023-11-03 07:45 AM
I did
2023-11-03 10:14 AM
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
the main.cpp
example.h
example.c
BR