问题遇到的现象和发生背景
怎么链接上这些, ubuntu 上安装了这些头文件 , 有知道怎么编译么
问题相关代码
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main()
{
glewExperimental = true;
if (! glewInit()) {
fprintf(stderr, "初始化 glew 失败!!");
return -1;
}
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // We don't want the old OpenGL
GLFWwindow* window;
window = glfwCreateWindow(500, 500, "window1", NULL, NULL);
if (window == NULL) {
fprintf(stderr, "创建 window 失败!!");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window); // 初始化 glew
glewExperimental = true;
if (glewInit() != GLEW_OK) {
fprintf(stderr, "Failed to initialize GLEW\n");
return -1;
}
}
运行结果及报错内容
g++ -o main window.cpp
/usr/bin/ld: /tmp/ccTfugXe.o: in function `main':
window.cpp:(.text+0xe): undefined reference to `glewExperimental'
/usr/bin/ld: window.cpp:(.text+0x14): undefined reference to `glewInit'
/usr/bin/ld: window.cpp:(.text+0x56): undefined reference to `glfwWindowHint'
/usr/bin/ld: window.cpp:(.text+0x65): undefined reference to `glfwWindowHint'
/usr/bin/ld: window.cpp:(.text+0x74): undefined reference to `glfwWindowHint'
/usr/bin/ld: window.cpp:(.text+0x83): undefined reference to `glfwWindowHint'
/usr/bin/ld: window.cpp:(.text+0x92): undefined reference to `glfwWindowHint'
/usr/bin/ld: window.cpp:(.text+0xb3): undefined reference to `glfwCreateWindow'
/usr/bin/ld: window.cpp:(.text+0xe3): undefined reference to `glfwTerminate'
/usr/bin/ld: window.cpp:(.text+0xf6): undefined reference to `glfwMakeContextCurrent'
/usr/bin/ld: window.cpp:(.text+0xfc): undefined reference to `glewExperimental'
/usr/bin/ld: window.cpp:(.text+0x102): undefined reference to `glewInit'
collect2: error: ld returned 1 exit status