[arm-gnu] Static linking with clock_gettime
Robert PINSKER
robert.pinsker at st.com
Mon Sep 17 16:20:02 UTC 2012
You are quite right, thanks, I should have thought of that.
Robert.
-----Original Message-----
From: Carlos O'Donell [mailto:carlos_odonell at mentor.com]
Sent: 17 September 2012 15:33
To: Robert PINSKER; arm-gnu at codesourcery.com
Subject: Re: [arm-gnu] Static linking with clock_gettime
On 9/17/2012 10:12 AM, Robert PINSKER wrote:
> Thanks for your really fast reply!
>
> The link command & the error message is as follows:
>
> /design/HED_A9SS/CodeSourcery/Sourcery_G++_Lite/2011.03/bin/arm-none-l
> inux-gnueabi-gcc
> -O3 -DUSE_CLOCK=0 -DUSE_FORK=1 -lrt -funroll-loops -fgcse-sm
> -falign-loops=8 -combine -mfloat-abi=soft -mfpu=vfp3 -Iarm -I.
> -DFLAGS_STR=\""-O3 -DUSE_CLOCK=0 -DUSE_FORK=1 -lrt -funroll-loops
> -fgcse-sm -falign-loops=8 -combine -mfloat-abi=soft -mfpu=vfp3
> -DCORE_DEBUG=1 -static "\" -DITERATIONS=0 -DCORE_DEBUG=1
> core_list_join.c core_main.c core_matrix.c core_state.c core_util.c
> arm/core_portme.c -o ./coremark.exe -static
> /tmp/ccDw13Kv.o: In function `main':
> core_list_join.c:(.text+0x558c): undefined reference to `clock_gettime'
> core_list_join.c:(.text+0x55a0): undefined reference to `clock_gettime'
> core_list_join.c:(.text+0x618c): undefined reference to `clock_gettime'
> core_list_join.c:(.text+0x61a0): undefined reference to `clock_gettime'
> /tmp/ccDw13Kv.o: In function `start_time':
> core_list_join.c:(.text+0x93cc): undefined reference to `clock_gettime'
> /tmp/ccDw13Kv.o:core_list_join.c:(.text+0x93dc): more undefined
> references to `clock_gettime' follow
> collect2: ld returned 1 exit status
> make: *** [compile] Error 1
Please keep the list in the CC, that way others can learn from your questions.
Link order matters in a static link.
The file core_list_join.c has an undefined reference to `clock_gettime', but you have no *subsequent* static archive on the link list that provides the definition.
Move `-lrt' to the end of the command line to provide a definition *after* the reference that needs it.
If you can't change the link order you can work around this using --whole-archive, but this will increase your binary size by including things you may not need from the library.
If you ever have circular references look at --start-group/--end-group.
Cheers,
Carlos.
--
Carlos O'Donell
Mentor Graphics / CodeSourcery
carlos_odonell at mentor.com
carlos at codesourcery.com
+1 (613) 963 1026
More information about the arm-gnu
mailing list