C++ Direct2D - 从笔记本电脑移动正弦文件后出现链接器错误 2019

C++ Direct2D - Linker error 2019 after moving sine files from my laptop

本文关键字:链接 2019 错误 文件 Direct2D 笔记本 电脑 移动 C++      更新时间:2023-10-16

我想将我在笔记本电脑上编写的一些代码移动到另一台 PC 上。我没有使用Github或任何其他类型的源代码管理,我只是简单地将c ++文件复制到USB驱动器上并将它们放在我的另一台PC上。

现在,由于某种原因,当我尝试运行代码时,我遇到了错误?

代码只是一个使用 direct2d 在窗口上绘制的类。

这是它的样子:

#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);
};

我得到的错误是这样的:

Error   LNK2019 unresolved external symbol _D2D1CreateFactory@16 referenced in function "long __cdecl D2D1CreateFactory(enum D2D1_FACTORY_TYPE,struct _GUID const &,void * *)" (?D2D1CreateFactory@@YAJW4D2D1_FACTORY_TYPE@@ABU_GUID@@PAPAX@Z)  ffff    c:Userssharkgamingdocumentsvisual studio 2015ProjectsffffffffGraphics.obj   1   

起初我以为这是因为我忘记链接到 d2d1.lib,但即使这样做了,我仍然收到错误?

那么,有谁知道为什么我会收到错误以及如何解决它?

好的,在谷歌上搜索了一两个小时后,我发现基本上添加了这个:

#pragma comment(lib,"d2d1.lib")

会解决我的问题。

但是我完全不知道为什么,因为我已经进入了链接器设置并将d2d1.lib添加到其他库文件中?

编辑:天哪,我刚刚想通了。我将库添加到 x64 构建设置而不是 x86 中。 -_-