【问题标题】:Error LNK2019 - My common C++ code is not working错误 LNK2019 - 我的常用 C++ 代码不起作用
【发布时间】:2013-09-09 09:14:28
【问题描述】:

我已经检查我的代码好几天了,更改一些代码以查看它们是否有效,尝试不同的方法来使用我的代码,但我仍然遇到那个烦人的 LNK2019 错误。

这是原来的错误信息。

Error 1 error LNK2019: unresolved external symbol "public: struct IDirect3DSurface9 * thiscall CRenderer::LoadSurface(wchar_t const *,unsigned long,struct IDirect3DDevice9 *)" (?LoadSurface@CRenderer@@QAEPAUIDirect3DSurface9@@PB_WKPAUIDirect3DDevice9@ @@Z) 在函数 "public: void __thiscall CGame::InitGame(struct HWND *,int,int,bool)" (?InitGame@CGame@@QAEXPAUHWND__@@HH_N@Z) J:\Workspace 中引用\水果复仇者联盟\Game.obj

这是我认为问题所在的代码。我在以前的项目中使用过这个代码。我只是不知道为什么这次没有成功。

渲染器.h

class CRenderer
{
public:
    IDirect3DTexture9* LoadTexture( LPCSTR FileName, D3DCOLOR Alpha, IDirect3DDevice9* Device );
    IDirect3DSurface9* LoadSurface( LPCWSTR FileName, D3DCOLOR Alpha, IDirect3DDevice9* Device );
};

渲染器.cpp

IDirect3DSurface9* CRenderer::LoadSurface( LPCWSTR FileName, D3DCOLOR Alpha, IDirect3DDevice9* Device )
{
    IDirect3DSurface9* Result = NULL;
    D3DXIMAGE_INFO Info;
    D3DXGetImageInfoFromFileW( FileName, &Info );
    Device->CreateOffscreenPlainSurface( Info.Width, Info.Height, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &Result, NULL );
    D3DXLoadSurfaceFromFileW( Result, NULL, NULL, FileName, NULL, D3DX_DEFAULT, Alpha, NULL );
    return Result;
}

Game.cpp

void CGame::InitGame( HWND hWnd, int Width, int Height, bool Windowed )
{
    //Initialize Includes
    Graphics.InitDirect3D( hWnd, Width, Height, Windowed );

    //Load Game Variables...

    //Load Game Media...
    MenuBackground = WWIRenderer.LoadSurface( L"Resource/MenuBackground.jpg", 0, Graphics.Direct3DDevice );
   //^
}

编辑:在有人问之前,我已经进行了一些搜索,但我找到的答案并没有那么有用。

【问题讨论】:

  • 您是否将 Renderer.cpp 文件添加到您的项目中?
  • 您是否安装了 DirectX SDK?
  • 谢谢 Uchia... 我已经找到了问题所在。问题是,我在 1 个解决方案中使用了 2 个项目。我正在尝试从另一个项目加载文件。我将修改我的项目以处理这两个问题,这样就不会再发生这种情况了。
  • 但是是否可以从另一个项目链接文件?
  • 如果您自己解决了问题,请将其添加为答案(这是允许的,实际上是鼓励的)。

标签: c++ directx-9 visual-c++-2010


【解决方案1】:

我没记错,如果您没有安装 DirectX SDK,就会出现此错误。所以你应该这样做,或者重新安装或更新它。

【讨论】:

  • 我已经安装了 DirectX SDK。
  • @Fuzsie,您确定它不是不完整的,不是最新的,或者可能已损坏?那么我出去了
【解决方案2】:

使用 MSVC++ 编译时,必须将每个源文件和头文件添加到解决方案资源管理器中,否则会出现 LNK2019 错误。谢谢Uchia。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多