LNK2019关于dll项目的解决方案
LNK2019 on a solution with a dll project
我正试图创建一个解决方案,其中一个项目是.exe
,另一个项目是一个简单的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;
}
注意:当我不调用hw.printHello();
时,解决方案编译得很好,但是当我调用它时,链接器生成:
错误1错误LNK2019:未解析的外部符号"__declspec(dllimport) public: void __thiscall hello_world::printHello(void)"(__imp_?printHello@hello_world@@QAEXXZ)在函数_wmain C:UsersusteinfeldDesktopPrivateStudentsYanaConsoleApplication1ConsoleApplication1ConsoleApplication1中引用。obj ConsoleApplication1
这个函数被定义为一个自由函数
void printHello()
它属于hello_world
类,所以你应该将它的作用域设置为
void hello_world::printHello()
{
std::cout << "Hello World" << std::endl;
}
相关文章:
- 运行同一解决方案的另一个项目的项目
- Dll在同一解决方案中从 c# 项目导入到 c++ 项目
- MS Visual Studio 解决方案结合了非托管C++项目和 C# 项目
- 在 Visual Studio 解决方案中设置所有项目的运行时库
- 如何在解决方案中生成多个项目之前执行流程
- C++不正确,不需要重新声明类成员变量 MFC 手工解决方案/项目 MS VS 2015
- 如何在不创建新配置的情况下对两个不同解决方案使用的一个项目使用不同的 #defines
- 如何使用 CMake 获得包含所有项目的 VS 解决方案和单个项目的解决方案
- 单元测试类无法在我要测试的同一解决方案中的另一个项目中找到类
- 在解决方案中的项目中使用时缺少 NuGet 包
- 用于在 Visual Studio 中为整个项目或解决方案定义带有参数的预处理器宏的选项
- 在同一解决方案中的项目之间传递 CStrings
- 将CMAKE项目添加到Visual Studio解决方案中
- 如何将解决方案中的项目从应用程序更改为静态库
- 使用解决方案上的msbuild来调用某些项目上的自定义目标
- CMAKE将新项目添加到解决方案中
- 在 Visual Studio 中为单个解决方案编译和使用多个项目
- 在同一解决方案但不同配置的另一个项目中使用一个类
- 一个解决方案,两个项目:如何从 Windows 应用程序调用控制台项目?C++
- 在Visual Studio 15社区中构建Lua的解决方案/项目结构