[CMake] Link order of object files

Mathias Lafeldt misfire at debugon.org
Wed Jun 23 08:45:38 EDT 2010


Alexander Neundorf wrote:
> On Tuesday 22 June 2010, Mathias Lafeldt wrote:
>> Alexander Neundorf wrote:
>>> On Monday 21 June 2010, Mathias Lafeldt wrote:
>>>> Hi,
>>>>
>>>> is there a way to tell CMake in which order to link in object files?
>>>>
>>>> For example, I got the following executable:
>>>>
>>>> 	ADD_EXECUTABLE(hello crt0.o hello.c)
>>>>
>>>> Using a disassembler, I can see that hello.c is compiled in before
>>>> crt0.o, but I want crt0.o to always be the first.
>>>>
>>>> Also, this gives me the same result:
>>>>
>>>> 	ADD_EXECUTABLE(hello hello.c crt0.o)
>>> Is this for some embedded system ?
>> It's for the MIPS R5900 processor aka Emotion Engine.
>>
>>> You may consider putting crt0.o in the CMAKE_C_LINK_EXECUTABLE variable
>>> for your target.
>> Thank you. I didn't know about CMAKE_C_LINK_EXECUTABLE, but it seems to
>> be suitable.
>>
>> Unfortunately, the only documentation I could find
>> (<http://www.cmake.org/Wiki/CMake_Useful_Variables>) is very limited and
>> I don't really know the meaning/origin of all variables in sharp (?)
>> braces. For example, what is the difference between <FLAGS> and
>> <CMAKE_C_LINK_FLAGS>?
>>
>> I found this in the eCos platform script:
>>
>> SET(CMAKE_C_LINK_EXECUTABLE    "<CMAKE_C_COMPILER>   <FLAGS>
>> <CMAKE_C_LINK_FLAGS>   <LINK_FLAGS> <OBJECTS> -o <TARGET> -nostdlib
>> -nostartfiles -L${ECOS_LIBTARGET_DIRECTORY} -Ttarget.ld  <LINK_LIBRARIES>")
> 
> It's also set in several of the platform cmake files in Modules/Platform/.
> 
> Alex

Thank you.

I learned that the variables in sharp braces are supplied by the
generator at use time - see Modules/CMakeCInformation.cmake.

-Mathias


More information about the CMake mailing list