如何解决如何解决预编译头文件错误
我正在制作一个游戏引擎,我正在使用预编译的头文件在项目中的各种文件中使用。但我收到两个错误:
-
查找预编译时出现错误 C1010 意外的文件结尾 标题。您是否忘记将 '#include "sepch.h"' 添加到您的 来源? G:\Sky\SkyEngine\SkyEngine\src\SkyEngine\Application.cpp 37
-
查找预编译时出现错误 C1010 意外的文件结尾 标题。您是否忘记将 '#include "sepch.h"' 添加到您的 来源? G:\Sky\SkyEngine\SkyEngine\src\SkyEngine\Log.cpp 25 我在下面添加了代码:
sepch.h
#pragma once #include<iostream> #include<memory> #include<utility> #include<algorithm> #include<functional> #include<string> #include<sstream> #include<vector> #include<unordered_map> #include<unordered_set> #ifdef SE_PLATFORM_WINDOWS #include <Windows.h> #endif
Application.h
#include "G:\Sky\SkyEngine\SkyEngine\src\sepch.h"
#include "Application.h"
#include "G:\Sky\SkyEngine\SkyEngine\src\SkyEngine\Events\ApplicationEvent.h"
#include "G:\Sky\SkyEngine\SkyEngine\src\SkyEngine\Log.h"
/*
The dllexport and dllimport storage-class attributes are
Microsoft-specific extensions to the C and C++ languages.
You can use them to export and import functions,data,and
objects to or from a DLL. These attributes explicitly define
the DLL's interface to its client,which can be
the executable file or another DLL. Also are Macros.
*/
namespace SkyEngine {
//carries SkyEngine's application.
Application::Application() {
}
Application::~Application() {
}
void Application::Run() {
WindowResizeEvent e(1280,720);
if (e.IsInCategory(EventCategoryApplication)) {
SE_TRACE(e);
}
if (e.IsInCategory(EventCategoryInput))
{
SE_TRACE(e);
}
while (true); // infinite running of application
}
}
Log.cpp
#include "G:\Sky\SkyEngine\SkyEngine\src\sepch.h"
#include "Log.h"
#include "spdlog/sinks/stdout_color_sinks.h"
//using namespace std;
namespace SkyEngine {
std::shared_ptr <spdlog::logger> Log::s_CoreLogger;
std::shared_ptr <spdlog::logger> Log::s_ClientLogger;
void Log::Init() {
spdlog::set_pattern("%^[%T] %n: %v%$");
/*[%T] timestamp ; %n is name of the logger ;
%v%$ message to be displayed.
All will be wrapped under correct color(message to be displayed)
*/
s_CoreLogger = spdlog::stdout_color_mt("SkyEngine"); //mt is multi-threading
s_CoreLogger->set_level(spdlog::level::trace);
s_ClientLogger = spdlog::stdout_color_mt("APP"); //mt is multi-threading
s_ClientLogger->set_level(spdlog::level::trace);
}
}
Premake5.lua
workspace "SkyEngine"
architecture "x64"
configurations {
"Debug","Release","dist"
}
outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}"
project "SkyEngine"
location "SkyEngine"
kind "SharedLib"
language "C++"
targetdir("bin/" .. outputdir .. "/%{prj.name}")
objdir("bin-int/" .. outputdir .. "/%{prj.name}")
pchheader "sepch.h"
pchsource "SkyEngine/src/sepch.cpp" --[[creates our pre-compiled header file.]]
files{
"%{prj.name}/src/**.h","%{prj.name}/src/**.cpp"
}
includedirs {
" %{prj.name}/src","%{prj.name}/vendor/spdlog/include"
}
filter "system:windows"
cppdialect "C++17"
staticruntime "On"
systemversion "latest"
defines{
"SE_PLATFORM_WINDOWS","SE_BUILD_DLL"
}
--[[PUTS DLL WHERE IT WANTS TO BE]]
postbuildcommands{
{"{copY} %{cfg.buildtarget.relpath} ../bin/" .. outputdir .. "/SandBox"}
}
filter "configurations:Debug"
defines "SE_DEBUG"
symbols "On"
filter "configurations:Release"
defines "SE_RELEASE"
optimize "On"
filter "configurations:dist"
defines "SE_disT"
optimize "On"
filter {"system:windows","configurations:Release"}
project "SandBox"
location "SandBox"
kind "ConsoleApp"
language "C++"
targetdir("bin/" .. outputdir .. "/%{prj.name}")
objdir("bin-int/" .. outputdir .. "/%{prj.name}")
files {
"%{prj.name}/src/**.h","%{prj.name}/src/**.cpp"
}
includedirs {
"SkyEngine/vendor/spdlog/include","SkyEngine/src"
}
--[[links to the main SkyEngine project/solution]]
links {
"SkyEngine"
}
filter "system:windows"
cppdialect "C++17"
staticruntime "On"
systemversion "latest"
defines {
"SE_PLATFORM_WINDOWS"
}
filter "configurations:Debug"
defines "SE_DEBUG"
symbols "On"
filter "configurations:Release"
defines "SE_RELEASE"
optimize "On"
filter "configurations:dist"
defines "SE_disT"
optimize "On"
Log.h
#pragma once
#include "G:\Sky\SkyEngine\SkyEngine\src\sepch.h"
#include "Core.h"
#include "spdlog/spdlog.h"
#include "spdlog/fmt/ostr.h"
namespace SkyEngine
{
class SKYENGINE_API Log
{
public:
static void Init(); //initialization
inline static std::shared_ptr < spdlog::logger>& GetCoreLogger() {
return s_CoreLogger;
}
inline static std::shared_ptr < spdlog::logger>& GetClientLogger() {
return s_ClientLogger;
}
private:
static std::shared_ptr <spdlog::logger> s_CoreLogger;
static std::shared_ptr <spdlog::logger> s_ClientLogger;
};
}
/*creating macros for Logging(info and warn)
SkyEngine::Log::GetCoreLogger()->warn("Initialized Log!");
SkyEngine::Log::GetClientLogger()->info("Hello!");
*/
// CORE LOG MACROS
#define SE_CORE_TRACE(...) :: SkyEngine::Log::GetCoreLogger()->trace(__VA_ARGS__)
#define SE_CORE_INFO(...) :: SkyEngine::Log::GetCoreLogger()->info(__VA_ARGS__)
#define SE_CORE_WARN(...) :: SkyEngine::Log::GetCoreLogger()->warn(__VA_ARGS__)
#define SE_CORE_ERROR(...) :: SkyEngine::Log::GetCoreLogger()->error(__VA_ARGS__) // ... for variable number of arguments
#define SE_CORE_TRACE(...) :: SkyEngine::Log::GetCoreLogger()->trace(__VA_ARGS__)
// CLIENT LOG MACROS
#define SE_TRACE(...) :: SkyEngine::Log::GetClientLogger()->trace(__VA_ARGS__)
#define SE_INFO(...) :: SkyEngine::Log::GetClientLogger()->info(__VA_ARGS__)
#define SE_WARN(...) :: SkyEngine::Log::GetClientLogger()->warn(__VA_ARGS__)
#define SE_ERROR(...) :: SkyEngine::Log::GetClientLogger()->error(__VA_ARGS__) // ... for variable number of arguments
#define SE_TRACE(...) :: SkyEngine::Log::GetClientLogger()->trace(__VA_ARGS__)
注意:如果我指定 #include "sepch.h",则会生成其他错误。所以,我在这里使用了完整的源路径。 这是预编译的头文件设置以及正在生成的错误:
**
编辑
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。