[英]Dll export symbol of function from static linked library
我將靜態庫包裝在Dll中,以隱藏許多實現的東西,因為只需要4-5個函數,並避免提供所有第三方庫和許多頭文件。 我似乎在將函數從靜態庫導出到dll時遇到問題。 靜態庫具有類似於以下內容的設置類/結構
struct FooSettings
{
bool Read(const std::string& file); // implemented in .cpp
bool Write(const std::string& file); // implemented in .cpp
// rest members, just plain types
};
在DLL方面
#include "FooSettings.h"
#if defined(WIN32) || defined(_WIN32)
#if defined(LIB_EXPORT)
// DLL Build, exporting symbols
#define LIB_API __declspec(dllexport)
#elif LIB_IMPORT
// DLL use, importing symbols
#define LIB_API __declspec(dllimport)
#endif
#endif
#ifndef LIB_API
#define LIB_API
#endif
class LIB_API LibSDK
{
public:
LibSDK();
~LibSDK();
FooSettings get() const noexcept;
void set(const FooSettings& settings) const noexcept;
void dummy()
{
foo.Read("");
}
private:
// etc...
};
我可以在“客戶端”端調用dummy()
,沒有任何問題,但是下面的代碼導致未解析的符號
FooSettings foo;
foo.Read("");
我希望FooSettings:Read至少可以導出,因為它是偽函數的一部分。 我想念什么嗎? 我的喜好是在沒有虛擬功能的情況下將其導出,但是我似乎無法使它以任何一種方式工作。
回到所有這些,答案實際上是在靜態庫構建中#define LIB_EXPORT,這也是我所沒有想到的。
我認為靜態.lib文件不需要這樣的東西,因為它們只是對象文件的捆綁包,因此不需要將其標記為導出。 顯然,如果要將函數從靜態庫導出到包裝dll,則需要它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.