cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE not including library files correctly

ADP1114
Associate II

I am very new to STM32CubeIDE as I am switching from Keil to Cube. I included a library for an lcd and added the path of the library. The IDE does not recognize any functions defined in the library as I get the error "undefined reference to " function.

No error or warning is given at the "#include" for my header file within my code.

Am I missing a step when adding a library?

Is there a tutorial that would explain how to add such a library for this IDE?

edit:

I managed to successfully add a library for HX711 load cell amplifier. The library can be found here:

https://github.com/freakone/HX711

After including the header file of the library, I copied the c-file to the project folder. That seemed to be all that had to be done (it was also successful with the lcd library).

Unfortunately my issue isn't completely resolved.

I am also working with VL53L0X distance sensors which is dependent on ST's API that they have developed for it. The VL53L0X has a lot of headers and c files that needs to be referenced to. I tried only copying the header and c files included in my main, but that still gives the "undefined reference to" error.

I right clicked on the project folder and went to properties. Under C/C++ Build I went to settings and the tool settings. In tool settings under MCU G++ Linker/Libraries I added the paths to the directories.

When I have finished adding the directories I "apply and close" then clean my project and the build it. I then get the error "cannot find -l" next to my added path.

The path I provide starts in my C drive (C:/). I don't know whether that has an influence?

Maybe CubeIDE only searches within its current directory?

Thanks to anyone who helps (and even reads) with my question.

18 REPLIES 18
ADP1114
Associate II

Since STM32CubeIDE is Eclipse based, I managed to find a tutorial on adding libraries for Eclipse:

http://wiki.eclipse.org/CDT/User/FAQ#Adding_C.2FC.2B.2B_External_Libraries

Following those instructions I managed to get rid of the original error and am currently fixing a few directory issues. I will update whether the instructions worked.

Ozone
Lead

> No error or warning is given at the "include."

A bit of dubious wording.

Linker libs need to be added to the list of linked libraries, not "included".

The syntax is Unix-like short and cryptic, i.e. "-lc" to link against libc.a.

Be aware that Keil libs and gcc libs are not compatible. IAR has, AFAIK, it's own library format.

CubeIDE is gcc-based.

The library I am trying to add is a c script with a header file. Aren't adding such libraries normally included in c (using #include)? With Keil after including the header file I added the path and added the c scripts to the project then it worked. I don't know where to add the path in CubeIDE to get it to work. I now followed the instructions on

https://wiki.eclipse.org/CDT/User/FAQ#Adding_C.2FC.2B.2B_External_Libraries

now I added the path under MCU G++ Linker/Miscellaneous, but I get a message that reads

c:\st\stm32cubeide_1.0.2\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.7-2018-q2-update.win32_1.0.0.201904181610\tools\arm-none-eabi\bin\ld.exe: cannot find (Path I included): Permission denied

followed by the following error:

collect2.exe: error: ld returned 1 exit status

> The library I am trying to add is a c script with a header file.

I don't know what a "C script" is supposed to mean. A link library is not pulled in via "# include" directive.

Accompanying header only declare the interface, an actual library is a collection of object files (objects) processed by the linker.

> c:\st\stm32cubeide_1.0.2\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.7-2018-q2-update.win32_1.0.0.201904181610\tools\arm-none-eabi\bin\ld.exe: cannot find (Path I included): Permission denied

Sounds like the linker executable is not there.

GrantW
Associate II

I have this working and was asked today for more details so I'm posting my response here in case it helps anyone else.

This code was adapted from the sample provided in the hx711 datasheet at https://cdn.sparkfun.com/assets/b/f/5/a/e/hx711F_EN.pdf

Note that this device does not use standard SPI protocol. You need to set up two GPIO pins like so:

 /*Configure GPIO pin : SDATA_Pin */

 GPIO_InitStruct.Pin = SDATA_Pin;

 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 HAL_GPIO_Init(SDATA_GPIO_Port, &GPIO_InitStruct);

 /*Configure GPIO pin : SCLK_Pin */

 GPIO_InitStruct.Pin = SCLK_Pin;

 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

 HAL_GPIO_Init(SCLK_GPIO_Port, &GPIO_InitStruct);

You have to make sure that your APB is configured so that the clock speed for these pins is about 3MHz, otherwise you get timing problems.

There are jumper pads (aka solder bridges) on the sparkfun board for sample speed (I'm using 80/sec). See the datasheet. I have gain set in the code to 128. (1 extra clock tick after reading the data).

Note the hack under "// wait 300 ns". You might need to change this if your processor is running at a different speed. I'm at 96MHz.

Finally, some pins do not provide a good clock signal. Test your SCLK pin with a scope for a solid 3.3 V.

Good luck.

// wait for result from HX711 and read it into a 32 bit buffer.

uint32_t CB_SPI_Receive (void) {

uint32_t buffer = 0U;

int i, j, k = 1;

// wait for SDATA to go lo

while (HAL_GPIO_ReadPin (SDATA_GPIO_Port, SDATA_Pin)) ;

// wait 300 ns

for (j = 0; j < 5; j++) k += 19;

// read 24 data bits

for (i = 0; i < 24; i++) {

  HAL_GPIO_WritePin (SCLK_GPIO_Port, SCLK_Pin, GPIO_PIN_SET);

  buffer <<= 1;

  HAL_GPIO_WritePin (SCLK_GPIO_Port, SCLK_Pin, GPIO_PIN_RESET);

  buffer += HAL_GPIO_ReadPin (SDATA_GPIO_Port, SDATA_Pin);

}

// generate one or 3 more clock pulse to set gain for next sample and set bit 23 before returning

buffer ^= 0x800000;

// for (i = 0; i < 2; i++) {

HAL_GPIO_WritePin (SCLK_GPIO_Port, SCLK_Pin, GPIO_PIN_SET);

HAL_GPIO_WritePin (SCLK_GPIO_Port, SCLK_Pin, GPIO_PIN_RESET);

// }

return buffer;

}

AMaha.2
Associate II

Hi all,

I am facing similar kind of situation. When the header file is included in the code it is not showing any errors but when built it does not recognize the hearder file included by giving errors for all the elements of the included heder file saying unknow type names. Any help would be appreciated.

I have even added the requred paths.

Please check the below screenshots of the error and added paths.

Thank you,

0693W000000VeWsQAK.jpg

0693W000000VeWnQAK.jpg

Hi All,

I am also facing same issue. Can anyone help on this please?

Thanks

GZeyf.1
Associate II

Hi! The same problem. If I create C++ project from .ioc file IDE don`t see #include function ( but see the included file) !

main.c

....

#include "project.h"

....

project.h

#ifndef SRC_PROJECT_H_

#define SRC_PROJECT_H_

#ifdef __cplusplus

extern "C" {

#endif

void Setup(void);

void Loop(void);

#ifdef __cplusplus

}

#endif

#endif /* SRC_PROJECT_H_ */

function Setup and Loop the compiler doesn't see them , as if they don't exist

But if I create project new STM32 project (not from .ioc file) all work true.

Who knows how to solve this bug !???

"But if I create project new STM32 project (not from .ioc file) " are you working with STM32CubeMX or STM32CubeIDE here ?

"all work true" means you have used File > New STM32 Project but which options then ? (Empty or STM32Cube project types ?)

Where is your project.h located on file system ? Possibly share a screen snaphot of your project showing includes setups and file structure ...

In meantime takes care could be same as : https://community.st.com/s/question/0D53W00000DJpGPSA1/file-added-and-path-added-but-still-get-no-such-file

Takes care about your include coloring ... Is such include setupeffective from Eclipse point of view already ? Please could you check if such line is leading to plain or grayed include like following snapshot ... if grayed means Eclipse not able to reach

 0693W000003BZiCQAW.jpg