控制linux動態連結程式庫匯出函數

來源:互聯網
上載者:User

控制linux動態連結程式庫匯出函數

在linux中,我們可以通過-fvisibility=default|internal|hidden|protected來控制匯出函數。

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

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 DLL's 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")))的函數才是對外可見的。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.