Header files are not linking properly (some variables/functions are undefined) but the project builds (vscode)
Posted: Tue Jun 13, 2023 5:11 am
Hello. I have this very weird issue for my project. I have noticed that some variables in my custom component .c file show up as undefined even though they are defined in .h file and included in the .c file.
But even though it shows as undefined, I can right click the variable and go to its definition and it will open up the corresponding header file for me which means that its actually linking properly but VScode for some reason thinks it is undefined.
See example below:
I have a "test" component that contains test.c and test.h and CMakeLists.txt: In test.h I have declared the following functions and variables:
And in my test.c I include the header and use those functions and enums but they show up as undefined: Even some standard esp-idf GPIO driver keywords show up as undefined!
Even though they show up as undefined, as I said, the project builds fine and I can even go to definition by rightclicking and it will open test.h where the variables are defined but I am not sure why the vscode complains about this. Please can someone help me solve this as it is very frustrating to see this. Thanks in advance!
But even though it shows as undefined, I can right click the variable and go to its definition and it will open up the corresponding header file for me which means that its actually linking properly but VScode for some reason thinks it is undefined.
See example below:
I have a "test" component that contains test.c and test.h and CMakeLists.txt: In test.h I have declared the following functions and variables:
Code: Select all
#ifdef CONFIG_IDF_TARGET_ESP32
#define GPIO_IA_1 GPIO_NUM_16
#define GPIO_IA_2 GPIO_NUM_4
#define GPIO_IB_1 GPIO_NUM_14
#define GPIO_IB_2 GPIO_NUM_12
#define IR_RIGHT GPIO_NUM_22
#define IR_LEFT GPIO_NUM_18
#define IR_MIDDLE GPIO_NUM_19
#define IR_MIDDLE_LEFT GPIO_NUM_23
#define IR_MIDDLE_RIGHT GPIO_NUM_21
#endif
enum motor_control_e{
COAST,
FORWARD,
BACKWARDS,
STOP
};
void motor_A_control(enum motor_control_e control);
void motor_B_control(enum motor_control_e control);
void motor_GPIO_setup();
And in my test.c I include the header and use those functions and enums but they show up as undefined: Even some standard esp-idf GPIO driver keywords show up as undefined!
Even though they show up as undefined, as I said, the project builds fine and I can even go to definition by rightclicking and it will open test.h where the variables are defined but I am not sure why the vscode complains about this. Please can someone help me solve this as it is very frustrating to see this. Thanks in advance!