即使我正确引用该函数,如何修复这些错误? [英] How do I fix these errors even though I am properly referencing to the function?
本文介绍了即使我正确引用该函数,如何修复这些错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是代码:
Engine.h
#ifndef _ENGINE_H
#define _ENGINE_H
# include < SFML\Graphics.hpp >
class 引擎
{
私有:
// SFML渲染窗口
sf :: RenderWindow *窗口;
// 初始化引擎
bool Init();
// 主游戏循环
void MainLoop();
// 呈现一帧
void RenderFrame();
// 处理用户输入
void ProcessInput();
// 更新所有引擎内部
void Update();
public :
Engine();
~Engine();
void Go(); // 启动引擎
};
#endif
Engine.cpp
include Engine.h
#include < SFML \ Graphics.hpp >
引擎::引擎()
{
}
引擎::〜引擎()
{
}
bool Engine :: Init()
{
window = new sf :: RenderWindow(sf :: VideoMode( 800 , 600 , 32 ), RPG);
if (!window)
return 假跨度>;
return true ;
}
void Engine :: RenderFrame()
{
}
void Engine :: ProcessInput()
{
sf :: Event evt;
// 遍历所有窗口事件
while (window-> pollEvent(evt))
{
if (evt.type == sf: :Event :: Closed)
window-> close();
}
}
void 引擎::更新()
{
}
void Engine :: MainLoop()
{
// 循环直到我们的窗口关闭
while (window-> ; isOpen())
{
ProcessInput();
Update();
RenderFrame();
}
}
void Engine :: Go()
{
if (!Init())
throw 无法初始化Engine;
MainLoop();
}
和Main.cpp
#include < Windows.h >
#include Engine.h
int WINAPI wWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PWSTR pCmdLine, int nCmdShow)
{
引擎*引擎= 新引擎();
尝试
{
engine-> Go();
}
catch ( char * e)
{
MessageBoxA(NULL,e, Exception Occured,MB_OK | MB_IConerror);
}
}
错误:
|| === Build:Debug Game Engine(编译器:GNU GCC编译器)=== |
obj \Debug \ Engine.o ||函数`ZN6Engine4InitEv ' :
C:\ Users\dento\Desktop\Game Engine \ Engine.cpp | 17 |未定义引用`_imp ___ ZN2sf9VideoModeC1Ejjj' |
C:\ Users\dento\Desktop\Game Engine\Engine.cpp | 17 |未定义引用`_imp ___ ZN2sf6StringC1EPKcRKSt6locale ' |
C:\ Users\dento\Desktop\Game Engine \ Engine.cpp | 17 |未定义引用`_imp ___ ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE' |
obj \Debug \ Engine.o ||函数`ZN6Engine12ProcessInputEv ' :
C:\ Users\dento\Desktop\Game Engine \ Engine.cpp | 31 |未定义引用`_imp ___ ZN2sf6Window9pollEventERNS_5EventE' |
C:\ Users\dento\Desktop\Game Engine \ Engine.cpp | 37 |未定义引用`_imp ___ ZN2sf6Window5closeEv ' |
obj \Debug \ Engine.o ||函数`ZN6Engine8MainLoopEv':|
C:\ Users\dento\Desktop\Game Engine \ Engine.cpp | 47 |未定义引用`_imp ___ ZNK2sf6Window6isOpenEv ' |
C:\ Users\dento\Desktop\Game Engine \ Engine.cpp | 47 |未定义引用`_imp ___ ZN2sf6Window9pollEventERNS_5EventE' |
obj \Debug \ Engine.o ||函数`ZN6Engine12ProcessInputEv ' :
C:\ Users\dento\Desktop\Game Engine \ Engine.cpp | 37 |未定义引用`_imp ___ ZN2sf6Window5closeEv' |
obj \Debug \ Engine.o ||函数`ZN6Engine2GoEv ' :
C:\ Users\dento\Desktop\Game Engine \ Engine.cpp | 59 |未定义引用`_imp ___ ZNK2sf6Window6isOpenEv' |
C:\ Users\dento\Desktop\Game Engine\Engine.cpp | 59 |未定义引用`_imp ___ ZN2sf6Window9pollEventERNS_5EventE ' |
obj \Debug \ Engine.o ||函数`ZN6Engine12ProcessInputEv':|
C:\ Users\dento\Desktop\Game Engine \ Engine.cpp | 37 |未定义引用`_imp ___ ZN2sf6Window5closeEv ' |
C:\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libmingw32.a(main.o ):(。text.startup + 0xa0)||未定义引用`WinMain @ 16' |
||错误:ld返回 1 退出状态|
|| ===构建失败: 13 错误, 0 警告(s )( 0 分钟, 1 秒(s))=== |
只是注意到其中一些属于.o文件的错误。我该如何解决这个问题?
我的尝试:
我试过更改名称,我试图找到它没有引用的内容,除了我不知道该尝试什么。
解决方案
您没有链接到所需的库。如果包含所有必需的库,请检查项目设置。
您也可以在SFML论坛中获得更好的帮助:SFML社区论坛 - 索引 [ ^ ]。
但请先检查现有问题。他们可能会解决您的问题。这个帖子可能会有所帮助:构建失败; '未定义引用..' [ ^ ]
Here is the code:
Engine.h
#ifndef _ENGINE_H
#define _ENGINE_H
#include <SFML\Graphics.hpp>
class Engine
{
private:
//SFML Render Window
sf::RenderWindow* window;
//Initializes the engine
bool Init();
//Main Game Loop
void MainLoop();
//Renders one frame
void RenderFrame();
//Processes user input
void ProcessInput();
//Updates all Engine internals
void Update();
public:
Engine();
~Engine();
void Go(); //Starts the engine
};
#endif
Engine.cpp
include "Engine.h"
#include <SFML\Graphics.hpp>
Engine::Engine()
{
}
Engine::~Engine()
{
}
bool Engine::Init()
{
window = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "RPG");
if(!window)
return false;
return true;
}
void Engine::RenderFrame()
{
}
void Engine::ProcessInput()
{
sf::Event evt;
//Loop through all window events
while(window->pollEvent(evt))
{
if(evt.type == sf::Event::Closed)
window->close();
}
}
void Engine::Update()
{
}
void Engine::MainLoop()
{
//Loop until our window is closed
while(window->isOpen())
{
ProcessInput();
Update();
RenderFrame();
}
}
void Engine::Go()
{
if(!Init())
throw "Could not initialize Engine";
MainLoop();
}
and Main.cpp
#include <Windows.h>
#include "Engine.h"
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
Engine* engine = new Engine();
try
{
engine->Go();
}
catch(char* e)
{
MessageBoxA(NULL, e, "Exception Occured", MB_OK | MB_IConerror);
}
}
Errors:
||=== Build: Debug in Game Engine (compiler: GNU GCC Compiler) ===|
obj\Debug\Engine.o||In function `ZN6Engine4InitEv':|
C:\Users\dento\Desktop\Game Engine\Engine.cpp|17|undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'|
C:\Users\dento\Desktop\Game Engine\Engine.cpp|17|undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'|
C:\Users\dento\Desktop\Game Engine\Engine.cpp|17|undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'|
obj\Debug\Engine.o||In function `ZN6Engine12ProcessInputEv':|
C:\Users\dento\Desktop\Game Engine\Engine.cpp|31|undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'|
C:\Users\dento\Desktop\Game Engine\Engine.cpp|37|undefined reference to `_imp___ZN2sf6Window5closeEv'|
obj\Debug\Engine.o||In function `ZN6Engine8MainLoopEv':|
C:\Users\dento\Desktop\Game Engine\Engine.cpp|47|undefined reference to `_imp___ZNK2sf6Window6isOpenEv'|
C:\Users\dento\Desktop\Game Engine\Engine.cpp|47|undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'|
obj\Debug\Engine.o||In function `ZN6Engine12ProcessInputEv':|
C:\Users\dento\Desktop\Game Engine\Engine.cpp|37|undefined reference to `_imp___ZN2sf6Window5closeEv'|
obj\Debug\Engine.o||In function `ZN6Engine2GoEv':|
C:\Users\dento\Desktop\Game Engine\Engine.cpp|59|undefined reference to `_imp___ZNK2sf6Window6isOpenEv'|
C:\Users\dento\Desktop\Game Engine\Engine.cpp|59|undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'|
obj\Debug\Engine.o||In function `ZN6Engine12ProcessInputEv':|
C:\Users\dento\Desktop\Game Engine\Engine.cpp|37|undefined reference to `_imp___ZN2sf6Window5closeEv'|
c:\mingw\bin\..\lib\gcc\mingw32\4.9.3\..\..\..\libmingw32.a(main.o):(.text.startup+0xa0)||undefined reference to `WinMain@16'|
||error: ld returned 1 exit status|
||=== Build failed: 13 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|
just noticed in the errors that some of them are in the .o file. How would I fix this?
What I have tried:
I have tried changing the names, I have tried to find what it is saying I didn't reference, other than that I don't know what to try.
解决方案
You are not linking against the required libraries. Check your project settings if all necessary libraries are included.
You might also get better help in the SFML forums: SFML community forums - Index[^].
But check existing questions first. They might solve your problem. This thread that might help: Build fails; 'undefined reference to..'[^]
这篇关于即使我正确引用该函数,如何修复这些错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文