C ++:在定义时获取未解析的外部符号

问题描述 投票:0回答:1

所以我正在用C ++(和GLFW,但这没关系)编写一个输入处理程序,并且未在标头中实现的功能会丢弃这些错误:

1>Application.obj : error LNK2019: unresolved external symbol "public: static class Input & __cdecl Input::GetInstance(void)" (?GetInstance@Input@@SAAAV1@XZ) referenced in function _main
1>Application.obj : error LNK2019: unresolved external symbol "public: bool __thiscall Input::Init(class Window const &)const " (?Init@Input@@QBE_NABVWindow@@@Z) referenced in function _main
1>Application.obj : error LNK2019: unresolved external symbol "public: bool __thiscall Input::Update(void)" (?Update@Input@@QAE_NXZ) referenced in function _main

它们在Application.cpp中这样称呼:

Input::GetInstance().Init(window);
Input::GetInstance().Update();

实现是这样的:

Input.h:

#ifndef INPUT_H_INCULDED
#define INPUT_H_INCLUDED

//Some includes

class Input
{
public:
    static Input& GetInstance();

    bool Init(const Window& window) const;
    bool Update();
  //some other stuff
};

#endif

以及Input.cpp中的实现:

Input& Input::GetInstance()
{
return instance;
}

bool Input::Init(const Window& window) const
{
glfwSetFramebufferSizeCallback(window.getWindow(), framebuffer_size_callback);
glfwSetKeyCallback(window.getWindow(), invoke_callback);

return true;
}

bool Input::Update()
{
scrollOffset = 0;

pushedKeys.clear();
keysHolding.clear();
pushedButtons.clear();
buttonsHolding.clear();

return true;
}

instance,其他字段是带有getter和setter的Input的私有成员,并且回调函数在Input.cpp中定义我有问题,还有glfw libs,并包含在解决方案目录中一个名为Dependencies的文件夹中。我将其包含在C / C ++ \ General \ Additional Include Directories下的项目属性中,然后将它们链接起来,最后添加了GLEW_STATIC预处理程序语句。这些是我对项目属性所做的唯一更改,并且我使用了Debug配置和x86。到源代码的链接:https://github.com/Andrispowq/Prehistoric-Engine---C-

c++ linker definition
1个回答
0
投票

为了正确构建您的项目,您必须构建所有c ++文件。结果,您将以obj文件的形式获得与机器语言等效的内容。然后,为了使您的项目可执行文件,您必须正确链接所有这些obj文件。

如果您提供编译和链接项目的方式,那么我们可以解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.