我不能完全弄清楚哪里有错误。我正在创建一个 DLL,然后在 C++ 控制台程序(Windows 7、VS2008)中使用它。但是我LNK2019 unresolved external symbol
在尝试使用 DLL 函数时得到了。
首先是导出:
#ifndef __MyFuncWin32Header_h
#define __MyFuncWin32Header_h
#ifdef MyFuncLib_EXPORTS
# define MyFuncLib_EXPORT __declspec(dllexport)
# else
# define MyFuncLib_EXPORT __declspec(dllimport)
# endif
#endif
这是我随后使用的一个头文件:
#ifndef __cfd_MyFuncLibInterface_h__
#define __cfd_MyFuncLibInterface_h__
#include "MyFuncWin32Header.h"
#include ... //some other imports here
class MyFuncLib_EXPORT MyFuncLibInterface {
public:
MyFuncLibInterface();
~MyFuncLibInterface();
void myFunc(std::string param);
};
#endif
然后是控制台程序中的dllimport,它的DLL包含在Linker->General->Additional Library Directories中:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
__declspec( dllimport ) void myFunc(std::string param);
int main(int argc, const char* argv[])
{
std::string inputPar = "bla";
myFunc(inputPar); //this line produces the linker error
}
我不知道这里出了什么问题;它必须是非常简单和基本的东西。