我想创建一个解决方案,其中一个项目是.exe
和另一个项目是一个简单的dll
。我想要学习的是如何链接两个项目。我已搜查堆栈溢出,发现我所遵循非常好的答案,比如宣布在右侧头部浴:LNK2019解决方案与dll项目
Properties
- >Configuration Properties
- >C/C++
- >General
- >Additional Include Directories
然后设置的.lib上:
Properties
- >Configuration Properties
- >Linker
- >Input
- >Additional Dependencies
我用宏来生成.lib
文件。这里是我的简化代码:
的.exe
: CPP:
#include "stdafx.h"
#include "../ConsoleApplication2/HelloWorld.h"
int _tmain(int argc, _TCHAR* argv[])
{
hello_world hw;
hw.printHello();
getchar();
return 0;
}
的DLL: 头:
#pragma once
#ifdef is_hello_world_dll
#define hello_world_exp __declspec(dllexport)
#else
#define hello_world_exp __declspec(dllimport)
#endif
class hello_world_exp hello_world
{
public:
hello_world();
~hello_world();
void printHello();
};
CPP:
#include "stdafx.h"
#include "HelloWorld.h"
#include <iostream>
hello_world::hello_world()
{
}
hello_world::~hello_world()
{
}
void printHello()
{
std::cout << "Hello World" << std::endl;
}
的注意事项:解决方案编译罚款时,我不打电话然而当我做调用它,链接器将生成:
错误1个错误LNK2019:无法解析的外部符号 “__declspec(dllimport的)市民:无效__thiscall程序hello_world :: printHello(无效)”?(__imp_ printHello @程序hello_world @ @QAEXXZ)函数_wmainç引用:\用户\ usteinfeld \桌面\私人\学生\雅娜\ ConsoleApplication1 \ ConsoleApplication1 \ ConsoleApplication1.obj ConsoleApplication1
我有一种感觉,它是这样的。一旦时限到了,我会尽快回复!谢谢! – Steinfeld