简体   繁体   English

静态库“未定义的引用”到对象构造函数

[英]Static Library “Undefined Reference” to object constructor

I'm having this issue where I cannot call the object constructor in main.cpp even after it has been included in main.h. 我遇到了一个问题,即使将它包含在main.h中,也无法在main.cpp中调用对象构造函数。 The error message is: 错误消息是:

C:\Users\Espresso\Projects\AZRA\Debug/../src/main.cpp:7: undefined reference to `g_editor::LevelEditor::LevelEditor()'

Where main.cpp contains 其中main.cpp包含

#include "main.h"
g_editor::LevelEditor g_levelEditor;

and main.h contains: 并且main.h包含:

#include "g_editor/g_editor.h"

g_editor.h contains all of the header files of the objects in the library, which includes the levelEditor. g_editor.h包含库中对象的所有头文件,其中包括levelEditor。 g_editor.h: g_editor.h:

#ifndef G_EDITOR_H_
#define G_EDITOR_H_
#pragma once

#include "g_editor/Objects/editor_module.h"
#include "g_editor/Objects/utility_window.h"
#include "g_editor/Objects/prompt_window.h"
#include "g_editor/LevelEditor/LevelEditor.h"

extern g_editor::LevelEditor g_levelEditor;

#endif

And finally, LevelEditor.h contains the constructor and member functions of LevelEditor: 最后,LevelEditor.h包含LevelEditor的构造函数和成员函数:

#ifndef G_LEVEL_EDITOR_H_
#define G_LEVEL_EDITOR_H_
#pragma once

#include "../Objects/editor_module.h"
#include "Modules/collisionGrid_module.h"
#include "Modules/HUD_module.h"
#include "Modules/IO_module.h"
#include "Modules/ledge_module.h"
#include "Modules/segment_module.h"
#include "g_level/g_level.h"

using namespace g_level;
namespace g_editor
{
    class LevelEditor
    {
        private:
            std::vector<editor_module*> modules;
            void loadModules();

        public:
            static LevelEditor& get()
            {
                static LevelEditor sSingleton;
                return sSingleton;
            }
            LevelEditor();
            ~LevelEditor() {};

I apologize for the wall of text, I've been staring at this for a few days now and I have tried reordering the static libraries by precedence (which eliminated all issues save for this one.) Is there a design flaw in my current setup? 我为文字墙表示歉意,我已经盯着这几天了,我尝试按优先顺序对静态库进行重新排序(这消除了除此问题以外的所有问题。)我当前的设置中是否存在设计缺陷? I am using sSingletons, global externs, and static libraries. 我正在使用sSingletons,全局extern和静态库。

There is no definition of LevelEditor::LevelEditor . 没有LevelEditor::LevelEditor定义。

You are either missing a source file, or you forgot to add {} . 您或者缺少源文件,或者忘记添加{}

Edit: or, if your constructor does not do anything anyway, just remove the declaration. 编辑:或者,如果您的构造函数仍然不执行任何操作,则删除声明。

Either

1) This function is missing: 1)缺少此功能:

LevelEditor();  // So now what does this do????  That's what is missing.

or 要么

2) it isn't missing, but you didn't add the source module or library where this function is located to your linker settings. 2)它没有丢失,但是您没有将此功能所在的源模块或库添加到链接器设置中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM