2016-04-24 129 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; 
}