我创建一个DLL,并提供入口点FastString
类使用CreateFastString
功能:错误LNK2019:无法解析的外部符号功能_CreateFastString引用_wmain
FastString.h
:
#define EXPORT __declspec(dllexport)
#define IMPORT __declspec(dllimport)
class FastString
{
const int m_length;
char* m_str;
public:
FastString(const char* str);
~FastString();
int Length()const;
int Find(const char* str)const;
};
extern "C" FastString* CreateFastString(const char* str);
FastString.cpp
:
#include "stdafx.h"
#include <string>
#include "FastString.h"
FastString* CreateFastString(const char* str)
{
return new FastString(str);
}
FastString::FastString(const char* str): m_length(strlen(str)),
m_str(new char[m_length+1])
{}
FastString::~FastString()
{
delete[] m_str;
}
int FastString::Length()const
{
return m_length;
}
int FastString::Find(const char* str)const
{
return 1;
}
main.cpp
:
#include "stdafx.h"
#include <iostream>
#include "FastString.h"
int _tmain(int argc, _TCHAR* argv[])
{
FastString* str = CreateFastString("Hello Dll");
std::cout<<"The length is "<<str->Length()<<std::endl;
return 0;
}
在编译过程中,我收到以下错误:
TeatApp.obj : error LNK2019: unresolved external symbol _CreateFastString referenced in function _wmain
D:\MFC\FastString\Debug\TeatApp.exe : fatal error LNK1120: 1 unresolved externals
在Linker -> Input -> Additional Dependencies
我已经提供了.lib
文件的路径。
任何人都可以建议发生了什么问题。提前致谢。
您忘记正确使用'EXPORT'和'IMPORT'。 – 2013-05-13 17:16:29
@haroogan即使我声明类EXPORT FastString它仍然没有帮助。 – 2013-05-13 17:41:45
我正在为你准备一个答案,坚持下去。 – 2013-05-13 17:42:23