Undefined reference to UDS functions

A free API for the communication with control devices according to UDS (ISO 14229-1)
Post Reply
ValeV

Undefined reference to UDS functions

Post by ValeV » Wed 21. Apr 2021, 15:00

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:

F.Vergnaud
Software Development
Software Development
Posts: 305
Joined: Mon 9. Sep 2013, 12:21

Re: Undefined reference to UDS functions

Post by F.Vergnaud » Wed 21. Apr 2021, 16:22

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.
Best regards,
Fabrice

ValeV

Re: Undefined reference to UDS functions

Post by ValeV » Thu 22. Apr 2021, 10:11

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!

Post Reply