close

在linkage時, 會需要用-l來指明要加入那些libraries (archives)

例如 -lAAA -lBBB 這樣的順序

表示請 ld 將 libAAA.a 跟libBBB.a 這兩個libraries包進來

(請注意-lAAA 代表 libAAA.a, 別以為是AAA就是完整檔名)

萬一libAAA.a 裡面有去呼叫某個function body放在 libBBB.a

這樣的順序就會造成ld會找不到function body,而出現 undefined reference的錯誤訊息

最簡單的解決方式就是自己調整成 -lBBB -lAAA的順序,

 

不過萬一libraries很多呢?

總不能一增加function就一直調來調去吧?!

 

這時候就需要 --start-group archives --end-group  把archives不用依照順序包起來, 

讓ld自己去找dependency, 只不過這在linkage較花時間 (比起開發時間, 這一點點時間應該微不足道吧!)

 

看一下官方的說明......

 

--start-group archives --end-group

The archives should be a list of archive files. They may be either explicit file names, or ‘-l’ options. The specified archives are searched repeatedly until no new undefined references are created. Normally, an archive is searched only once in the order that it is specified on the command line. If a symbol in that archive is needed to resolve an undefined symbol referred to by an object in an archive that appears later on the command line, the linker would not be able to resolve that reference. By grouping the archives, they all be searched repeatedly until all possible references are resolved. Using this option has a significant performance cost. It is best to use it only when there are unavoidable circular references between two or more archives.

 

 

arrow
arrow
    文章標籤
    gnu library
    全站熱搜

    Orion 發表在 痞客邦 留言(0) 人氣()