尝试使用 glLoadGen 时出现链接错误
Link error while trying to use glLoadGen
在阅读OpenGL 4着色语言食谱时,我遇到了OpenGL Loader Gen库,并立即想尝试一下。我开始创建一个小的示例程序,你可以在下面看到。
#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 Subdirectory/*.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)
这是我的实际问题:如何让上面显示的程序使用前面提到的 OpenGL Loader Gen 库进行编译?
来自文档
上面的命令行将生成 gl_core_3_3.h 和 gl_core_3_3.c 文件。只需将它们包含在您的项目中;没有要构建的库,没有要过滤的未解析的外部。
您需要运行他们的生成器来生成这些源文件。
相关文章:
- 静态数据成员的问题-修复链接错误会导致编译器错误
- Visual Studio mkl_link_tool.exe链接错误
- C++ 实现模板单例类时出现链接错误
- 使用类模板的方法链接错误
- MySQL C++连接器链接错误
- VS 2015 链接错误 无法构建依赖于 libcurl 的项目
- 运行 C++ 单元测试时LNK2005链接错误
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 链接错误,包括我创建的相同头文件 - C++
- 在Embarcadero C++ Builder中生成的DLL未解决的外部链接错误
- 使用标头保护的多个定义链接错误
- 链接错误:未定义对 stdscr 和 wgetch 的引用
- 使用 Vivek 的 Vcam / 捕获源过滤器构建/链接错误
- 升压program_options中的链接错误
- 使用 g++ 预处理器进行替换会导致链接错误
- 在调试配置中编译工作正常,但发布会给出链接错误
- 相邻矩阵设置链接错误
- 包含常量变量并包含在多个文件中的标头的链接错误
- C++链接错误,我理解但无法解决
- 是什么导致macOS Mojave上的GoogleTest链接错误