C++;Direct2D-从笔记本电脑中移动正弦文件后发生链接器错误 我想把我在笔记本电脑上写的代码移到我的另一个PC.上,我没有使用GITHUB或任何其他类型的源代码控制,我只是简单地把C++文件复制到USB驱动器上,并把它们放在我的另一个PC上。
现在,由于某种原因,当我尝试运行代码时,我得到了一个错误 该代码只是一个使用direct2d在窗口上绘制的类 这就是它看起来的样子:C++;Direct2D-从笔记本电脑中移动正弦文件后发生链接器错误 我想把我在笔记本电脑上写的代码移到我的另一个PC.上,我没有使用GITHUB或任何其他类型的源代码控制,我只是简单地把C++文件复制到USB驱动器上,并把它们放在我的另一个PC上。,c++,windows,visual-studio,directx,C++,Windows,Visual Studio,Directx,现在,由于某种原因,当我尝试运行代码时,我得到了一个错误 该代码只是一个使用direct2d在窗口上绘制的类 这就是它看起来的样子: #pragma once #include <Windows.h> #include <d2d1.h> #include <iostream> #include "LinkedList.h" class Graphics { private: ID2D1Factory* pFactory; ID2D1Hwn
#pragma once
#include <Windows.h>
#include <d2d1.h>
#include <iostream>
#include "LinkedList.h"
class Graphics
{
private:
ID2D1Factory* pFactory;
ID2D1HwndRenderTarget* pRenderTarget;
ID2D1SolidColorBrush* pBrush;
RECT bounds;
float lineWidth = 5.0f;
LinkedList pointList;
public:
Graphics();
~Graphics();
void BeginDraw() { pRenderTarget->BeginDraw(); };
void EndDraw() { pRenderTarget->EndDraw(); };
void SetBrushColor(float r, float g, float b, float a);
void SetBrushColor(float r, float g, float b);
void SetLineWidth(float width);
RECT GetBounds();
void ClearScreen(float r, float g, float b, float a);
void ClearScreen(float r, float g, float b);
void FillCircle(float x, float y, float radius);
void DrawCircle(float x, float y, float radius);
void FillRect(float x, float y, float w, float h);
void DrawRect(float x, float y, float w, float h);
void MoveTo(float x, float y);
void LineTo(float x, float y);
void tester();
bool Init(HWND* pWindowHandle);
};
起初我认为这是因为我忘记链接到d2d1.lib,但即使这样做了,我仍然会得到错误
那么,有人知道我为什么会出错以及如何修复吗?好的,
在谷歌搜索了一两个小时后,我发现基本上添加了以下内容:
#pragma comment(lib,"d2d1.lib")
可以解决我的问题
但我完全不知道为什么,因为我已经进入链接器设置并将d2d1.lib添加到其他库文件中了
编辑:天哪,我刚想出来。
我将库添加到x64构建设置中,而不是x86-_- 在任何查看器(甚至在记事本中)中打开您的
d2d1.lib
,然后搜索_D2D1CreateFactory@16
完全正确(或对于\uu imp__D2D1CreateFactory@16
)-认为您没有找到此字符串(链接器找不到它)这意味着您有旧版本的d2d1.lib
-因此您需要下载并安装最新的SDK,但我刚刚检查了我的DirectX版本,它说我有DirectX 11,所以我不认为是这样:(这是因为visual studio没有链接到d2d1.lib文件,即使我进入设置并将其添加到附加库文件中。d2d1.lib
绝对独立于DirectX版本-这是绝对不同的事情。好吧。但您在开始时说,即使链接到d2d1.lib
所以我假设这是旧库,不包含_D2D1CreateFactory@16
#pragma comment(lib,"d2d1.lib")