Undefined Reference in Unit Test Project

Sysprogs forums Forums VisualGDB Undefined Reference in Unit Test Project

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #30183
    carneytom1981
    Participant

    I am creating a unit test project using TinyEmbeddedTest. The main project in my solution builds and runs fine, but I am getting some linker errors on the unit test project.

    The unit tests are in a source file called ADC.cpp, in the unit test project.  This file tests code in a file named ADC.c (which is in my main project) and so has the line:

    #include “ADC.c”

    The file ADC.c contains the following include lines:

    #include “ADC.h”
    #include “fault.h”

    The errors are thrown in ADC.c, on the following statements:

    if (status == SUCCESS)
    {
    Fault_Clear(FAULT_ADC_FAILURE);
    rawADCValue = HAL_ADC_GetValue(hADC);
    }
    else
    {
    Fault_Set(FAULT_ADC_FAILURE);
    rawADCValue = 0u;
    }

    The errors are:

    undefined reference to ‘Fault_Clear’

    undefined reference to ‘Fault_Set’

    From this I can see that the header file, fault.h, where these functions are declared, is accessible to the toolchain, because otherwise there would be a compilation error, but the source file. fault.c, where these functions are defined, does not seem to be accessible.

    I do not get these errors when running my main project, only in the unit test project.

     

    I thought that perhaps the answer might lie in the project linker settings, and so I added a line to the Linker->[Additional Inputs] as follows:

    C:\Development\myProject\VisualGDB\Debug\Src

    I assumed that this would give the linker access to the .o files, created by the compiler. Unfortunately this created a new problem. The build now fails without any error messages. The list of build messages simply says

    Build failed: arm-none-eabi-g++.exe exited with code 1

    Id returned 1 exit status

    and when I look at the log, it says

    c:/sysgcc/arm-eabi/bin/../lib/gcc/arm-none-eabi/9.3.1/../../../../arm-none-eabi/bin/ld.exe: cannot find C:/Development/myProject/VisualGDB/Debug/Src: Permission denied

    Interestingly, that last path is a hyperlink, and when I click on it, I get an error dialog box

    Failed to open ‘C:\SysGCC\arm-eabi\Development\myProject\VisualGDB\Debug\Src’

    This is especially odd, because I know that path does not exist, and that is definitely not the path that I entered in the Linker settings.

    Any guidance would be much appreciated.

    #30184
    support
    Keymaster

    Hi,

    No problem, please see the following tutorial for a detailed explanation of the “undefined reference” errors: https://visualgdb.com/tutorials/linux/libraries/diagnosing/

    There is also another one that explains a similar issue for the embedded projects: https://visualgdb.com/tutorials/tips/externc/

    #30187
    carneytom1981
    Participant

    Hi, thanks for your reply.

    Sorry, I should have specified in my original post, I have already wrapped all relevant header and source files with

    #ifdef __cplusplus
    extern "C" {
    #endif
    
    // code
    
    #ifdef __cplusplus
    }
    #endif

    Unfortunately, the Undefined Reference problem persists.

    #30189
    support
    Keymaster

    Sorry, the “undefined reference” is not something specific to VisualGDB. It’s an error shown by the linker if the project does not include definitions (not declarations) of the referenced symbols. The best thing we can offer via our regular product support is the 2 tutorials linked above. They explain the differences between the definitions and declarations in detail. We would advise taking time to follow them and go through the diagnostic steps described there, as it will help you get a better understanding of the logic behind handling of references.

    If you believe the issue is on the VisualGDB side, please try reproducing it from scratch (including creating a new project) and documenting every step. If you could share all the steps with the relevant screenshots, we can try to pinpoint the most likely cause of the issue.

    We can also review your specific project and point out the locations of the declarations/definitions of the symbols, and adjust the settings to include all the necessary files, however as it’s something specific to the project, we would have to charge a consulting fee for it. Feel free to contact our sales if you would like to get a quote.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.