新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 控制linux動態(tài)鏈接庫導(dǎo)出函數(shù)

控制linux動態(tài)鏈接庫導(dǎo)出函數(shù)

作者: 時間:2016-11-22 來源:網(wǎng)絡(luò) 收藏
linux中,我們可以通過-fvisibility=default|internal|hidden|protected來控制導(dǎo)出函數(shù)。

在GCC幫助文檔 -fvisibility=default|internal|hidden|protected參數(shù)下有這樣一段描述:

本文引用地址:http://m.butianyuan.cn/article/201611/320008.htm

a superior solution made possible by this option to marking things hidden when the default is public is to make the default hidden and mark things public. This is the norm with DLLs on Windows and with -fvisibility=hidden and "__attribute__ ((visibility("default")))" instead of "__declspec(dllexport)" you get almost identical semantics with identical syntax. This is a great boon to those working with cross-platform projects.

需要了解的是,在linux下,源文件中的所有函數(shù)都有一個默認的visibility屬性,即為public,在編譯命令中加入 -fvisibility=hidden參數(shù),會將所有默認的public的屬性變?yōu)閔idden。此時,如果對函數(shù)設(shè)置__attribute__ ((visibility("default")))參數(shù),使特定的函數(shù)仍然按默認的public屬性處理,則-fvisibility=hidden參數(shù)不會對該函數(shù)起作用。所以,設(shè)置了-fvisibility=hidden參數(shù)之后,只有設(shè)置了__attribute__ ((visibility("default")))的函數(shù)才是對外可見的。



評論


技術(shù)專區(qū)

關(guān)閉