C++ 尝试使用glLoadGen时出现链接错误
在阅读时,我遇到了图书馆,并立即想尝试一下。我开始创建一个小的示例程序,您可以在下面看到C++ 尝试使用glLoadGen时出现链接错误,c++,opengl,C++,Opengl,在阅读时,我遇到了图书馆,并立即想尝试一下。我开始创建一个小的示例程序,您可以在下面看到 #include "GLFW/glfw3.h" #include "GL/gl_core_4_1.hpp" namespace engine { class Window { private: const unsigned int width; const unsigned int height; const char *titl
#include "GLFW/glfw3.h"
#include "GL/gl_core_4_1.hpp"
namespace engine
{
class Window
{
private:
const unsigned int width;
const unsigned int height;
const char *title;
const void refresh()
{
glfwSwapBuffers(this -> glfwWindow);
glfwPollEvents();
}
protected:
GLFWwindow *glfwWindow;
public:
Window(const unsigned int width, const unsigned int height, const char title[]): width(width), height(height), title(title)
{
if (glfwInit() != GLFW_TRUE)
{
throw "Couldn't initialise the required GLFW library.";
}
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
if (this -> glfwWindow)
{
throw "Cannot create a secondary window.";
}
this -> glfwWindow = glfwCreateWindow(this -> width, this -> height, this -> title, NULL, NULL);
// This is the crucial line that will stop the program from compiling.
gl::exts::LoadTest context = gl::sys::LoadFunctions();
if (!context)
{
throw "Couldn't initialse the required GL library.";
}
glfwMakeContextCurrent(this -> glfwWindow);
glfwSwapInterval(GLFW_TRUE);
if (!glfwWindow)
{
glfwTerminate();
throw "Couldn't create a new initially empty window.";
}
}
const bool await()
{
this -> refresh();
if (glfwWindowShouldClose(this -> glfwWindow))
{
glfwDestroyWindow(this -> glfwWindow);
glfwTerminate();
return false;
}
return true;
}
};
}
int main(const int argc, const char *argv[])
{
engine::Window window(1280, 720, "Foundation");
while (window.await())
{
}
return 0x00000000;
}
我的下一步是尝试在运行macOS High Sierra操作系统的计算机上使用LLVM
编译器编译程序
clang++-o Application.exec子目录/*.cpp-lglfw-framework Cocoa-framework OpenGL-framework IOKit-framework CoreVideo
但是,在编译过程中,我收到以下意外链接器错误:
Undefined symbols for architecture x86_64:
"gl::sys::LoadFunctions()", referenced from:
engine::Window::Window(unsigned int, unsigned int, char const*) in Application-58a670.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
下面是我的实际问题:如何让上面显示的程序使用前面提到的库进行编译?来自
上面的命令行将生成gl_core_3_3.h和gl_core_3_3.c文件。只需将它们包含在项目中;没有要构建的库,也没有要过滤的未解析外部
您需要运行它们的生成器来生成这些源文件 谢谢你的快速回复。我对
C++
比较陌生,我有一个问题想问你:当我像这样包含库时:\35;包含“gl_core_4_1.hpp”
程序不会编译,但是当我包含.cpp
文件时,程序执行得很好!为什么会这样?没有足够的信息来回答这个问题。错误是什么?您选择了哪种生成样式?在“生成样式”下定义了什么?生成脚本的-style
参数。但是你的错误是什么?当然!现在我明白你的意思了!在构建这两个文件时,我实际上使用了指针\u cpp
。显示的唯一错误已经在问题本身内部。它不存在与“代码”相关的问题。只有include似乎是“错误的”。对于所有试图解决此问题的人来说:在使用官方页面上显示的LUA
编译源代码后,不要包含gl\u core\u x\u x.hpp
文件,只需包含构建成功完成后创建的另一个.cpp
文件即可。我还必须在LUA
脚本中包含以下行:unpack=table.unpack
就在脚本的最后一行之前。