Re: [問題] Singleton 與 DLL
※ 引述《adxis (acer)》之銘言:
總算找出來到底是哪邊的問題了 => 忘了加上 define variable 0rzzzz
在VC上面,如果用了 _declspec(dllexport)
在使用 dll 的檔案 (client) 最好還是要 _declspec(dllimport)
也就是編譯 client 的時候記得下相對應的 define 參數
LokiExport.h 裡面是以 LOKI_MAKE_DLL 跟 LOKI_DLL 來區分
我則是偏好下面貼的方式 (出處 http://gcc.gnu.org/wiki/Visibility )
不管編 lib 或是 client 都只要define DLL 即可
#ifndef _DLLEXPORT_H
#define _DLLEXPORT_H
// Generic helper definitions for shared library support
#if defined WIN32 || defined __CYGWIN__
#define HELPER_DLL_IMPORT __declspec(dllimport)
#define HELPER_DLL_EXPORT __declspec(dllexport)
#define HELPER_DLL_LOCAL
#else
#if __GNUC__ >= 4
#define HELPER_DLL_IMPORT __attribute__ ((visibility("default")))
#define HELPER_DLL_EXPORT __attribute__ ((visibility("default")))
#define HELPER_DLL_LOCAL __attribute__ ((visibility("hidden")))
#else
#define HELPER_DLL_IMPORT
#define HELPER_DLL_EXPORT
#define HELPER_DLL_LOCAL
#endif
#endif
#ifdef DLL
#ifdef DLL_EXPORTS
#define API HELPER_DLL_EXPORT
#else
#define API HELPER_DLL_IMPORT
#endif // DLL_EXPORTS
#define LOCAL HELPER_DLL_LOCAL
#else // DLL is not defined: build static lib.
#define API
#define LOCAL
#endif // DLL
#endif
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.123.218.30
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章