xTIMEcomposer 14 Linker Error

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
gerrykurz
XCore Addict
Posts: 204
Joined: Sun Jun 01, 2014 10:25 pm

xTIMEcomposer 14 Linker Error

Post by gerrykurz »

I have a function that when it is defined in the source file from which it is called; compiles, links and runs correctly.

When the same function is defined in a different source file, and included with #include statement, it still compiles correctly but generates the a linker error.

Here is the code that build, links and runs correctly all from the same source file:

Function Definition:

Code: Select all

void print_hex_character_local (unsigned char character)
{
if (character < 16) printstr("0");
printhex(character);
}

void print_packet_local (unsigned char packet[], unsigned int packet_length)
{
printstr("Length = ");
printuintln(packet_length);

unsigned int array_index = 0;

while (array_index < packet_length)
{
if ((array_index % 16) == 0)
{
printstr("\n");
print_hex_character_local(array_index >> 8);
print_hex_character_local(array_index);
printstr(" ");
}
print_hex_character_local(packet[array_index]);
printstr(" ");
array_index++;
}
printstr("\n\n");
}
Function call:

Code: Select all

print_packet_local(buf, 48);
Here is the function definition from a different source file:

Code: Select all

void print_hex_character (unsigned char character)
{
if (character < 16) printstr("0");
printhex(character);
}

void print_packet (unsigned char packet[], unsigned int packet_length)
{
printstr("Length = ");
printuintln(packet_length);

unsigned int array_index = 0;

while (array_index < packet_length)
{
if ((array_index % 16) == 0)
{
printstr("\n");
print_hex_character(array_index >> 8);
print_hex_character(array_index);
printstr(" ");
}
print_hex_character(packet[array_index]);
printstr(" ");
array_index++;
}
printstr("\n\n");
}
Here is the prototype from the include header file (custom_print.h):

Code: Select all

void print_packet (unsigned char packet[], unsigned int packet_length);
Here is the include statement from the calling source file:

Code: Select all

#include "custom_print.h"
Here is function call:

Code: Select all

print_packet(buf, 48);
And finally here is the linker error message:
Creating App_500_Rack.xe
D:/CSSD Documents/XMOS/Workspace/500Rack3PortTest/module_gptp/src/gptp.xc: Error: Undefined reference to '_Sprint_packet_0'
xmake[1]: *** [bin//App_500_Rack.xe] Error 1
xmake: *** [bin//App_500_Rack.xe] Error 2
Any idea why this is happening?


User avatar
larry
Respected Member
Posts: 275
Joined: Fri Mar 12, 2010 6:03 pm

Post by larry »

I'm not sure what the problem could be.

I would debug by creating a small test case that reproduces the issue. Intermediate files in your .build directory can help with this as well as verbose make output when VERBOSE=1 is set.

Or try changing function names, files or place of declaration/definition to see what is a factor and what isn't.
User avatar
myndideal
Active Member
Posts: 59
Joined: Thu May 05, 2011 10:00 pm
Location: Budapest

Post by myndideal »

hi,
do you use .xc, .c and .cpp files too?
Which one is declare and define your function.
Your function probably definied in a .cpp file, therefore it was compiled as a c++ function, but before the definition there wasn't an extern "C" prefix loaded some reason...
So you declare two different functions, but realized only one of them. Typical reason if some of the header includes another in wrong order.
User avatar
gerrykurz
XCore Addict
Posts: 204
Joined: Sun Jun 01, 2014 10:25 pm

Post by gerrykurz »

Not using cpp
srinie
XCore Addict
Posts: 158
Joined: Thu Mar 20, 2014 8:04 am

Post by srinie »

It looks to retain the old reference somehow in the incremental build.
Did you try a clean and build of the project?
User avatar
gerrykurz
XCore Addict
Posts: 204
Joined: Sun Jun 01, 2014 10:25 pm

Post by gerrykurz »

Yes
User avatar
myndideal
Active Member
Posts: 59
Joined: Thu May 05, 2011 10:00 pm
Location: Budapest

Post by myndideal »

I badly asked, so there's no cpp file... But is it xc and c files? So does it used and definied in different kind of source file ? Because I am just wondering if xc use some function name mangling when the xc kind of array parameter is used ... Probably I am wrong, but something I remember that way...

The caller is on the same module or these are on different libs and/or app ?

Is it any extern keyword there before the function declaration?


To find similar problems, I did add -save-temps option into makefile's XCC_FLAGS key to keep the temporary files. Other possible useful option could be, to get the map file from the linker by something like this:
XCC_MAP_FLAGS= -Xmapper --map -Xmapper $(APP_NAME).map