如何使用C/C++動態庫與靜態庫中的宏

來源:互聯網
上載者:User

標籤:如何使用   port   bsp   export   c/c++   添加   blog   efi   標頭檔   

  在哪個cpp檔案中使用的該動態庫或靜態庫,就在該h/cpp檔案所在的工程的預先處理命令中添加庫中的宏。

如有庫工程add,其標頭檔如下

#ifndef _ADD_H#define _ADD_H#if defined( _WIN32 ) || defined( __MINGW32__ )#   if defined( ADD_EXPORTS )#       define ADD_EXPORT __declspec(dllexport)#   elif defined( ADD_USE_DLL_IMPORT ) || !defined( ADD_USE_STATIC_LIB )#       define ADD_EXPORT __declspec(dllimport)#   else#       define ADD_EXPORT#   endifADD_EXPORT int add(int a, int b);#endif

則VS上編譯動態庫時,需要在add工程的預先處理指令中增加ADD_EXPORTS。

 

另有測試工程test:若其要使用動態庫中的add函數,則其工程中需要使用 ADD_USE_DLL_IMPORT 預先處理指令。

如何使用C/C++動態庫與靜態庫中的宏

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.