keyword:
compiler options,gcc,static lib and linker
在使用外部協力商所給的lib(static lib)出現了..
Cannot link object as its attributes are incompatible with the image attributes
原本,以為是那邊給錯了..所以試著去查了一下它的內容.用gnu Binutils(ar,nm)
看看是那邊有問題,依著Linker Error 可能原因有
a.alignment
b.endian
c.different --fpu
但,看起來這幾項都不應該出現.
除了去信要求協力商再次檢查其lib 外.
而其中,原本是懷疑是c ,即它可能用到float point運算.
A.
但,我還是得先以gcc Binutils(ar and nm)去看一下是不是它原本就有問題.像是給錯或檔案毀壞. 其結果如下.
fig . readelf . to check the ABI versiion and endian
fig. ar . static lib to check the conatin .
fig . nm ; to show the symbol
由上可得出,能排及b (endian)及obj file 毀壞.
而我還是不能得到它的原因.因此
請其它同事以不同的案子去試著linker. 卻是正常的
所以看了一下它的環境,才得出這個答案.enum container always int
B.
在disable 原本在compiler對於enum container always int 設定後.
C陷阱篇之enum默认长度 以這篇所敘述的內容.
"enum是一种数据类型,使用时会检查类型匹配".因此
enum长度不确定会带来可移植性问题,如果第三方库API接口使用enum类型,编译和调用库时一旦有关enum长度的编译器设置不一致,API接口层对数值的解析就不匹配。比如上层应用编译时没有用-fshort-enums,默认用4字节空间来存储使用enum变量,而编译库时设置了fshort-enums,则库内部此enum size可能为1。当把enum变量地址传进API时,内部只修改变量最低字节,高3字节值无变化(内容随机),API返回时,上层使用的4字节enum变量值就可能随机。(潜规则篇之API接口)
"因此内部代码使用enum类型优于define,但对外API接口尽量避免用enum型。"
C.
那麻,這個問題要如何由gcc Binutils 去檢查?
它是由對外的API 所宣告的enum所造成的,因此首先就是對所有對於的API (nm 中的T)
但我自己建立lib後,卻不論是否有enable enum container always int 其程式也是可以動作??而且以objdump 也沒看到它有去檢查??
D.
最後,在未來建立自己的Lib及使用它人的Lib這些都需要特別注意
C潜规则篇之API接口
http://blog.csdn.net/ipmux/article/details/17309277
ref:
Linker Error: L6242E: Cannot link object <objname> as its attributes are incompatible with the image attributes.
http://infocenter.arm.com/help/topic/com.arm.doc.faqs/ka4223.html
gnu gcc basic
https://docs.google.com/document/d/1rKNprDiocE094tU3xq_waHIN-tHpY_Tuum84pSoTEZE/edit?usp=sharing
http://infocenter.arm.com/help/topic/com.arm.doc.dui0491f/Babjddhe.html
https://answers.launchpad.net/gcc-arm-embedded/+question/224724
http://infocenter.arm.com/help/topic/com.arm.doc.dui0348c/CHDIBFAB.html