2016-04-24 82 views
0

我正在嘗試創建一個C++ dll。我遵循了msdn教程,但我無法正確編譯我的dll。不能用Visual Studio導出C++ dll

問題是任何函數都被導出。我已用dumpbin.exe工具和nm工具對其進行了測試。

在這兩種情況下,都沒有檢測到符號。

下面是這個庫的代碼:

頭文件

#ifndef NLIB_H 
#define NLIB_H 

#ifdef _WINDLL 
#define NLIB_EXPORTS __declspec(dllexport) 
#else 
#define NLIB_EXPORTS __declspec(dllimport) 
#endif 

#ifdef __cplusplus 
extern "C"{ 
#endif 

    NLIB_EXPORTS int fun1(int n); 

#ifdef __cplusplus 
} 
#endif 

#endif 

源代碼文件:

#include "nlib.h" 

int fun1(int n) { 
    return 100; 
} 
+2

你定義'_WINDLL'當您生成的dll? – Thomas

+0

是的,如果您選擇動態庫作爲項目類型,則由Visual Studio定義。另外,VS 2013指出了哪些宏定義了,我確信'_WINDLL'正在工作。 – Dan

+0

'_WINDLL'在哪裏定義 - 在某個頭文件中,還是在項目設置中? – Andy

回答

2

我已經發現的錯誤。這是必要添加NLIB_EXPORTS*.c文件還,是這樣的:

#include "nlib.h" 

NLIB_EXPORTS int fun1(int n) { 
    return 100; 
}