【发布时间】:2020-04-29 16:36:19
【问题描述】:
我开始尝试开发游戏引擎。结果,我无法编译!请告诉我应该修复或添加什么以便我可以编译 DLL?我注意到我是 C++ 的初学者,这是我第一次尝试在 C++ 中创建 DLL 库。
所以。该项目有以下 CPP 文件:dllmain.cpp(由 VS 生成)、Engine.cpp、pch.cpp、World Game Engine.cpp。该项目有头文件Engine.h。
Engine.h 代码:
#pragma once
#include <SFML/Graphics.hpp>
using namespace sf;
class Engine
{
private:
RenderWindow m_Window;
void input();
void update(float dtAsSeconds);
void draw();
public:
Engine();
void start();
};
Code of Engine.cpp:
#include "stdafx.h"
#include "Engine.h"
#include "pch.h"
Engine::Engine()
{
Vector2f resolution;
resolution.x = VideoMode::getDesktopMode().width;
resolution.y = VideoMode::getDesktopMode().height;
m_Window.create(VideoMode(resolution.x, resolution.y),
"World Game Engine",
Style::Fullscreen);
}
void Engine::start()
{
Clock clock;
while (m_Window.isOpen())
{
Time dt = clock.restart();
float dtAsSeconds = dt.asSeconds();
input();
update(dtAsSeconds);
draw();
}
}
Code of World Game Engine.cpp:
#include "stdafx.h"
#include "Engine.h"
#include "pch.h"
int init()
{
Engine engine;
engine.start();
return 0;
}
所以,我得到了很多错误。
我无法创建屏幕截图,因为我有俄罗斯版的 VS。但是如果有必要,我可以切换到英文版并截图。 SFML 已关联。
【问题讨论】:
-
你首先要解释为什么你不能。
-
你的编译器应该使用
stdafx.h或pch.h不能同时使用。无论您使用什么,它都必须是第一个包含。现代版本的 Visual Studio 将pch.h用于标准c++项目。 10 年以上的旧版本使用stdafx.h用于所有标准c++和 MFC。 -
项目由VS 2019生成,我可以假设一切都是正确的。
-
我可以假设一切都是正确的。代码在使用预编译头时不正确。您很可能希望摆脱
#include "stdafx.h"并将#include "pch.h"放在每个 .cpp 文件的顶部。