I modified the io-packet of qnx and calculating a timestamp in the recieve.c file at ip layer.


uint64_t ipStart_time, IPLatency;

EXPORT_SYMBOL(IPLatency); //I am using this in Linux

void rtl_receive ()


ipStart_time = clock_cycles();

IPLatency = ipStart_time;


I want to read that timestamp in my user program:

So I did :


extern uint64_t IPLatency;

But it is showing error: undefined reference to IPLatency


The extern keyword informs the compiler that it should expect a function or variable (symbol) to be defined in another of the linking objects. For a function this means that the compiler will not give an error if a function has not been implemented.

The error you get, undefined reference, indicates that the linker cannot find a exported symbol with that signature in any of the object files included in the linking.


I'm guessing a little bit here because there isn't a lot of information about where these respective files are. With that as a disclaimer here goes ....

You have edited a file that belongs to the Operating System Kernel and exported the symbol. That just makes the symbol visible to kernel modules that wish to link with the kernel and not to a userspace program. Your userspace program is not linked to the kernel and thus when you attempt to link the linker cannot find a reference to IPLatency and it exits.

The extern keyword tells the compiler that this symbol is external to this file, and so just assume it exists and let the linker worry about it. The purpose of the extern definition is so the compiler knows what the type of this variable is, and not to reserve memory for it. The linker needs to find all the symbols in order to turn a symbol in to an actual reference to the correct memory location. So an extern variable needs to be declared somewhere in the program that you are trying to link.

What you are attempting to do is transfer information from kernel space to userspace. This is going to be much more difficult, involving either a new system call or by making the information available via some other mechanism (e.g. sysfs). You will probably need to research some more and then ask another question about that (and the answer to that question will probably be beyond me).


The answer might be short: EXPORT_SYMBOL is used for exporting symbols inside the kernel, e.g. to other kernel modules. Your user space program would not have access to it, thus your linker would report a undefined reference error.

Suggestion: send the data via things like copy_to_user or write the information in /proc and let the userspace program read from it.