Header files are not linking properly (some variables/functions are undefined) but the project builds (vscode)

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

Header files are not linking properly (some variables/functions are undefined) but the project builds (vscode)

Postby zazas321 » 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:
test_component.png
test_component.png (8.27 KiB) Viewed 842 times
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:
showing_as_undefined.png
showing_as_undefined.png (28.47 KiB) Viewed 842 times
Even some standard esp-idf GPIO driver keywords show up as undefined!
showing_as_undefined_2.png
showing_as_undefined_2.png (27.4 KiB) Viewed 842 times
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!

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 133 guests