cancel
Showing results for 
Search instead for 
Did you mean: 

The problem is that the variables and header files declared in ".h" cannot be loaded from the ".c" file.

hans536
Associate III

I want to work by adding the c and h files I created.

The problem is that the variables and header files declared in ".h" cannot be loaded from the ".c" file.

Below is the situation I tested.

The c and h files I created are core.c and core.h.

not problem As shown in the figure, there was no problem when "components.h" and "stdio.h" were included in the core.c file and variables were declared.

However, an error occurred when variables declared in core.h and header files were included.

I would like to ask for help on how to solve it.

This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
1 ACCEPTED SOLUTION

Accepted Solutions
ODOUV.1
ST Employee

Hello, annyeonghaseyo,

the first quick work around is to use:

#include "../include/core.h"

0693W00000VO7tKQAT.png 

But I will look how to fix Makefile to extend include directories.

got bwayo

Best regards.

View solution in original post

5 REPLIES 5
KnarfB
Principal III

Defining a global variable in a header file often causes trouble and is generally not recommended or even forbidden in some domains, like MISRA C, see https://analyst.phyzdev.net/documentation/help/reference/misra.onedefrule.var.htm

There seems to be another issue in your code as the compiler warns about printf which should be declared in stdio.h. ...

hth

KnarfB

ODOUV.1
ST Employee

Hello, annyeonghaseyo,

the first quick work around is to use:

#include "../include/core.h"

0693W00000VO7tKQAT.png 

But I will look how to fix Makefile to extend include directories.

got bwayo

Best regards.

This is also true

the variable should be declared in the .h (extern uint8_t abcd;)

and instantiated in the .c (uint8_t abcd = 255;)

thank you

ODOUV.1
ST Employee

I found the root cause of your issue:

0693W00000VO8PzQAL.pngwe already have a core.h in our sample code

so you need to rename your file (eg mycore.h)

and include it

#include "mycore.h"

Best regards,

-Olivier