Page 1 of 1

Undefined reference to UDS functions

Posted: Wed 21. Apr 2021, 15:00
by ValeV
Heya,

I will be brief - my environment is Windows 10, CodeBlocks and mingw-w64. I created a C static library with 1 .h file and 1 .c file.

UDS_t.h has:

Code: Select all

#include "UDS/PCAN-UDS_2013.h"

#ifdef __cplusplus
extern "C" {
#endif

void test();

#ifdef __cplusplus
}
#endif
UDS_t.c has:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include "UDS/UDS_t.h"

void test()
{
    uds_status retval = UDS_Initialize_2013(PCANTP_HANDLE_USBBUS1, PCANTP_BAUDRATE_500K, 0, 0, 0);
}
I include this static library in new C++ console application, along with "Win32/PCAN-UDS.lib" and "x64/PCAN-UDS.lib". Console application's main function only calls

Code: Select all

test();
On compile, I get an error undefined reference to 'UDS_Initialize_2013'.

AFAIK function definitions are in .lib file that I included - so why does it not see it?

I am losing 1 full day on this, so I decided to ask for help. :oops:

Re: Undefined reference to UDS functions

Posted: Wed 21. Apr 2021, 16:22
by F.Vergnaud
Hello Valev,

This is a bit out of scope of our support as you have an issue with the configuration of your IDE/compiler but I would advise to double check your include path, library path and compiler command line.

Based on your #include (which are a bit messy), you have the following structure:
  • UDS
    • UDS
      • UDS
        • PCAN-ISO-TP_2016.h
        • PCAN-UDS_2013.h
      • UDS_t.h
    • UDS_t.c
  • main.c
The following command is working (I have PCAN-UDS.lib next to main.c for test purpose) :
"c:\mingw-w64\bin\gcc.exe" main.c UDS\UDS_t.c -l:PCAN-UDS.lib -L.

Re: Undefined reference to UDS functions

Posted: Thu 22. Apr 2021, 10:11
by ValeV
Thank you, you were correct. I double checked includes and found out that I linked PCAN-UDS.lib before my static library UDS_t.a. I turned them around and it works now. Thanks!