Because POSIX timer is used, librt (real-time dynamic library of glibc) must be dynamically linked during compilation ).
The-lrt parameter must be added to the makefile link:
Gcc-LrtA. o, B. o...-o my_program
This makefile runs well on the local machine. The system is Ubuntu 11.04 Desktop.
However, the following error occurs on the server:
My_timer.o: In function 'init _ my_timer ':
My_timer.c :(. text + 0x1bb): undefined reference to 'timer _ create'
My_timer.o: In function 'cel _ my_timer ':
My_timer.c :(. text + 0x220): undefined reference to 'timer _ settime'
My_timer.o: In function 'start _ my_timer ':
My_timer.c :(. text + 0x255): undefined reference to 'timer _ settime'
My_timer.o: In function 'Restart _ my_timer ':
My_timer.c :(. text + 0x28a): undefined reference to 'timer _ settime'
Collect2: ld returned 1 exit status
Make: *** [my_program] Error 1
Obviously, librt is not linked! Very strange, the server is a Linux ubuntu-wfms-slaver-02 3.0.0-15-server
However, you can use ldconfig-p to view all the dynamic libraries and see that there is a librt:
Librt. so.1 (libc6, x86-64, OS ABI: Linux 2.6.15) =>/lib/x86_64-linux-gnu/librt. so.1
Librt. so (libc6, x86-64, OS ABI: Linux 2.6.15) =>/usr/lib/x86_64-linux-gnu/librt. so
I am very puzzled by this question!
Accidentally put the-lrt parameter at the end:
Gcc a. o, B. o...-o my_program-Lrt
The result is successful ~ I don't quite understand why the parameter location has an impact.