我的问题是这样的:
当我自己构建Engine时,一切都很好,没有错误发生。
如果我构建整个解决方案,并且仅在“Game.cpp”中#include“Engine.h”或“util.h”(Game中具有主方法的源文件),那么它也可以工作,如果我在窗口中执行它打开并且调试输出也正确。
但是,如果我在“Game.cpp”中#include“Configuration.h”,则会出现标题中所述的错误。
我注意到这些文件之间的唯一区别是“Engine.h”和“util.h”不包含任何 vulkan 代码,而是它们的源文件对应项“Engine.cpp”和“util.cpp”包含,而“Configuration.h”包含任何 vulkan 代码。 h”包含#include“vulkan/vulkan.h”。
有人知道可能是什么问题以及如何解决它吗?
Engine.h
#pragma once
namespace re
{
class REngine
{
public:
void init();
};
}
引擎.cpp
#include "Engine.h"
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
//std
#include <iostream>
namespace re {
void REngine::init()
{
#ifdef _DEBUG
std::cout << "Realms Engine begin initializing." << std::endl;
#endif // _DEBUG
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow* window = glfwCreateWindow(800, 600, "Vulkan window", nullptr, nullptr);
uint32_t extensionCount = 0;
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
std::cout << extensionCount << " extensions supported\n";
glm::mat4 matrix;
glm::vec4 vec;
auto test = matrix * vec;
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
}
}
配置.h
#pragma once
#include "vulkan/vulkan.h"
namespace re {
class RConfiguration
{
private:
VkApplicationInfo m_appInfo;
const int m_height;
const int m_width;
public:
RConfiguration(
const char* name,
int height, int width,
int major, int minor, int patch
);
const int get_width() { return m_width; }
const int get_height() { return m_height; }
VkApplicationInfo get_app_info() { return m_appInfo; }
};
}
配置.cpp
#include "Configuration.h"
namespace re {
RConfiguration::RConfiguration(const char* name, int height, int width, int major, int minor, int patch): m_height(height), m_width(width)
{
m_appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
m_appInfo.pApplicationName = name;
m_appInfo.applicationVersion = VK_MAKE_VERSION(major, minor, patch);
m_appInfo.pEngineName = "Realms Engine";
m_appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
m_appInfo.apiVersion = VK_API_VERSION_1_2;
}
}
游戏.cpp
#include <iostream>
#include "Engine.h"
#include "util.h"
#include "Configuration.h"
int main()
{
std::cout << "Hello World!\n";
re::REngine engine;
auto version = re::util::make_version(1, 2, 1);
std::cout << version << std::endl;
engine.init();
}
re::RConfiguration make_config() {
return re::RConfiguration(
"Realms in the Sky",
600,
800,
1, 0, 0
);
}
如果你输入
sudo apt install libvulkan-dev
,这将使丑陋的错误消失,所有的vvill vvork!