cancel
Showing results for 
Search instead for 
Did you mean: 

How do i use Generated types in my linked library?

sde c.1
Senior II

Hi Coders,

i have added a library trough linked folders (Source location-> Link Folder..) where most of my code is in that i want to re-use in several projects.

But often i see that type's generated by the code generator (ioc) are not "seen" by my library.

The library is not compiled but exist of many c and header files.

To give a clear example :

Some main projects use the DAC, when i activate DAC in ioc, i get type DAC_HandleTypeDef to use in my main project.

In my library i have added code to create a member when DAC_HandleTypeDef exists like this :

#ifdef 	DAC_HandleTypeDef
	DAC_HandleTypeDef *pDAC_Speed;
#endif

This does not work, the libary code thinks the DAC_HandleTypeDef is not defined while i can use DAC_HandleTypeDef type in my mainproject.

I did follow the header sequence , and see that DAC_HandleTypeDef is defined trough "stm32g4xx_hal.h" which is the very first header in the main project. While my library headers should be compiled later.

What's going on?

How do you guys/girls solve this issue?

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

DAC_HandleTypeDef is a defined type (typedef struct ...). This is different to a defined preprocessor macro what you are testing for with #ifdef. There is no standard way in C to test wether a type exists or not.

What you could do, you could check wether the entire DAC module is included in your project with

#ifdef HAL_DAC_MODULE_ENABLED

defined (or not defined) in stm32g4xx_hal_conf.h

hth

KnarfB

View solution in original post

1 REPLY 1
KnarfB
Principal III

DAC_HandleTypeDef is a defined type (typedef struct ...). This is different to a defined preprocessor macro what you are testing for with #ifdef. There is no standard way in C to test wether a type exists or not.

What you could do, you could check wether the entire DAC module is included in your project with

#ifdef HAL_DAC_MODULE_ENABLED

defined (or not defined) in stm32g4xx_hal_conf.h

hth

KnarfB