Static Libraries and ZERO Warnings

引言

也许是时候停下脚步,整理一下我们在引擎开发中遗留的各种警告与问题了。我们将引擎构建为静态库,并且清除所有警告!

由于目前的进度和各种警告问题,我们需要将引擎改为静态库,而不是像 DOOM 一样引擎作为 dll,游戏再链接到该 dll 上,在未来我们会尝试采取此模式。

预生成文件

在 VSCode 中打开所有预生成文件。

Infinite

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
workspace "Infinite"
architecture "x64"
startproject "Sandbox"

configurations
{
"Debug",
"Release",
"Dist"
}

outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}"

-- Include directories relative to root folder (solution directory)
IncludeDir = {}
IncludeDir["GLFW"] = "Infinite/vendor/GLFW/include"
IncludeDir["GLAD"] = "Infinite/vendor/GLAD/include"
IncludeDir["ImGui"] = "Infinite/vendor/imgui"
IncludeDir["glm"] = "Infinite/vendor/glm"

include "Infinite/vendor/GLFW"
include "Infinite/vendor/GLAD"
include "Infinite/vendor/imgui"

project "Infinite"
location "Infinite"
kind "StaticLib"
language "C++"
+ staticruntime "on"
+ cppdialect "C++17"

targetdir ("bin/" .. outputdir .. "/%{prj.name}")
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")

pchheader "ifnpch.h"
pchsource "Infinite/src/ifnpch.cpp"

files
{
"%{prj.name}/src/**.h",
"%{prj.name}/src/**.cpp",
"%{prj.name}/vendor/glm/glm/**.hpp",
"%{prj.name}/vendor/glm/glm/**.inl"
}

+ defines
+ {
+ "_CRT_SECURE_NO_WARNINGS"
+ }


includedirs
{
"%{prj.name}/src",
"%{prj.name}/vendor/spdlog/include",
"%{IncludeDir.GLFW}",
"%{IncludeDir.GLAD}",
"%{IncludeDir.ImGui}",
"%{IncludeDir.glm}"
}

links
{
"GLFW",
"GLAD",
"ImGui",
"opengl32.lib"
}

filter "system:windows"
systemversion "latest"

defines
{
"IFN_PLATFORM_WINDOWS",
"IFN_BUILD_DLL",
"GLFW_INCLUDE_NONE"
}

filter "configurations:Debug"
defines "IFN_DEBUG"
runtime "Debug"
+ symbols "on"

filter "configurations:Release"
defines "IFN_RELEASE"
runtime "Release"
+ optimize "on"

filter "configurations:Dist"
defines "IFN_DIST"
runtime "Release"
+ optimize "on"



project "Sandbox"
location "Sandbox"
kind "ConsoleApp"
language "C++"
+ cppdialect "C++17"
+ staticruntime "on"



targetdir ("bin/" .. outputdir .. "/%{prj.name}")
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")

files
{
"%{prj.name}/src/**.h",
"%{prj.name}/src/**.cpp"
}

includedirs
{
"Infinite/vendor/spdlog/include",
"Infinite/src/Infinite",
"Infinite/src/Events",
"Infinite/src/**.h",
"Infinite/src/**.cpp",
"Infinite/vendor/imgui",
"%{IncludeDir.glm}"
}

links
{
"Infinite"
}

filter "system:windows"
systemversion "latest"

defines
{
"IFN_PLATFORM_WINDOWS"
}

filter "configurations:Debug"
defines "IFN_DEBUG"
runtime "Debug"
+ symbols "on"

filter "configurations:Release"
defines "IFN_RELEASE"
runtime "Release"
+ optimize "on"

filter "configurations:Dist"
defines "IFN_DIST"
runtime "Release"
+ optimize "on"

将引擎的预生成文件转化为 .lib 静态库。

ImGUI

之前出现的错误是由于我擅自修改了 imgui 的预生成文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
project "ImGui"
kind "StaticLib"
language "C++"
staticruntime "on"

targetdir ("bin/" .. outputdir .. "/%{prj.name}")
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")

files
{
"imconfig.h",
"imgui.h",
"imgui.cpp",
"imgui_draw.cpp",
"imgui_internal.h",
"imgui_tables.cpp",
"imgui_widgets.cpp",
"imstb_rectpack.h",
"imstb_textedit.h",
"imstb_truetype.h",
"imgui_demo.cpp"
}

filter "system:windows"
systemversion "latest"
cppdialect "C++17"
staticruntime "On"

filter { "system:windows", "configurations:Release" }
buildoptions "/MT"

GLAD

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
project "GLAD"
kind "StaticLib"
language "C"
staticruntime "on"

targetdir ("bin/" .. outputdir .. "/%{prj.name}")
objdir ("bin-int/" .. outputdir .. "/%{prj.name}")

files
{
"include/glad/glad.h",
"include/KHR/khrplatform.h",
"src/glad.c"
}

includedirs
{
"include"
}

filter "system:windows"
systemversion "latest"

filter "configurations:Debug"
runtime "Debug"
symbols "on"

filter "configurations:Release"
runtime "Release"
optimize "on"

类型转换

ImGuiLayer.cpp 还有一个类型转换的问题:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
	void ImGuiLayer::End()
{
ImGuiIO& io = ImGui::GetIO();

Application& app = Application::Get();
+ io.DisplaySize = ImVec2((float)app.GetWindow().GetWidth(), (float)app.GetWindow().GetHeight());

// Rendering
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
GLFWwindow* backup_current_context = glfwGetCurrentContext();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(backup_current_context);
}
}

调试

零报错零警告,引擎正常运行!