久久ER99热精品一区二区-久久精品99国产精品日本-久久精品免费一区二区三区-久久综合九色综合欧美狠狠

新聞中心

EEPW首頁 > 嵌入式系統 > 設計應用 > 控制linux動態鏈接庫導出函數

控制linux動態鏈接庫導出函數

作者: 時間:2016-11-22 來源:網絡 收藏
linux中,我們可以通過-fvisibility=default|internal|hidden|protected來控制導出函數

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

本文引用地址:http://cqxgywz.com/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下,源文件中的所有函數都有一個默認的visibility屬性,即為public,在編譯命令中加入 -fvisibility=hidden參數,會將所有默認的public的屬性變為hidden。此時,如果對函數設置__attribute__ ((visibility("default")))參數,使特定的函數仍然按默認的public屬性處理,則-fvisibility=hidden參數不會對該函數起作用。所以,設置了-fvisibility=hidden參數之后,只有設置了__attribute__ ((visibility("default")))的函數才是對外可見的。



評論


技術專區

關閉