简体   繁体   中英

Stubbing the HAL library for STM32 Unit tests

To get unit tests working for my STM32 project I am mocking the Hal library. So far we have managed to Mock it and create dummy files. However I am running into an issue. At this point we have 3 .h files, one for #defines, one for functions and the other is a straight copy of a HAL file. The program seems to compile and is giving me linking errors.

The error it is giving is "Multiple definition of", but not one error. Like roughly 200. It is giving an error on all the functions in hal_stub_functions.h It even seems to loop a couple of times. We have checked all files. None include the wrong files or each other. All files contain If/Def/Endif. The 3 files do not include each other. The functions file includes the #Defines file. I have no idea where to start looking for this. Tried the general stuff, as mentioned checking includes. Project settings are all correct. If anybody has any help or ideas id greatly appreciate it.

EDIT: Think I may have found something weird. Image here Seems like Eclipse is finding every function twice. On the same spot. How do i fix this?

EDIT 2: I think the general problem is that the linker is somehow finding files twice.

Thanks in advance :)

Solution: Make all functions static. As multiple files were including the .h file they were constantly redefining the functions. Even tho #ifdef was applied. #pragma once did not help either.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM