[英]Compiling example opengl application using c++ on linux terminal
So, as the title is pretty much explaining everything, let me tell why this does not work for me. 因此,标题几乎可以解释所有内容,因此,请告诉我为什么这对我不起作用。
I have a simple OpenGL application which I am supposed to compile and run using GLFW libraries. 我有一个简单的OpenGL应用程序,应该使用GLFW库进行编译和运行。 So far so good, I have downloaded and tested all OpenGL and GLFW libaries, among other libraries like GLUT. 到目前为止,我已经下载并测试了所有OpenGL和GLFW库,以及其他库(例如GLUT)。 When compiling the application through terminal, I also link the required libraries like so (I am not really sure which libararies required, that's why I put a bunch of them without a professional knowledge): 通过终端编译应用程序时,我还链接所需的库,如下所示(我不确定要使用哪个库,这就是为什么我把其中的一些库不具备专业知识的原因):
g++ -std=gnu++11 -lglut -lGL -lGLU -lGLEW -lglfw3 -lGL -lm -lXrandr -lXi -lX11 -lXxf86vm -lpthread main.cpp -o main -I external/include/
Let me share what ls
shows on that project's directory: 让我分享一下ls
在该项目目录上显示的内容:
external gl_app.hpp main.cpp models.hpp
gl_app.cpp gl_includes.hpp models.cpp Readme.md
The folder external
includes some headers that were included in the main.cpp
file. external
文件夹包含main.cpp
文件中包含的某些标头。 That is why I am also calling this folder. 这就是为什么我也称这个文件夹。
Here is the first ten lines of main.cpp
. 这是main.cpp
的前十行。 The "glm/*.hpp"
files are in the external
folder. "glm/*.hpp"
文件位于external
文件夹中。
#include "gl_app.hpp"
#include "models.hpp"
#include <glm/vec2.hpp>
#include <glm/mat4x4.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <iostream>
#include <memory>
#include <cmath>
And after all, here is the error message I get. 毕竟,这是我收到的错误消息。 It simply complains about the declarations. 它只是抱怨声明。 I have read many documentations and questions around, implementing many solutions of whom faced with very similar problem. 我阅读了许多文档和相关问题,实现了许多面临非常相似问题的解决方案。 Yet in my case the problem keeps remaining. 但就我而言,问题仍然存在。
Any help? 有什么帮助吗?
main.cpp: In member function ‘virtual bool gl_ifi::GlExample::init()’:
main.cpp:78:54: error: ‘glViewport’ was not declared in this scope
glViewport(0, 0, int(fbSize.x), int(fbSize.y));
^
main.cpp:87:53: error: ‘glCreateShader’ was not declared in this scope
vertShader = glCreateShader(GL_VERTEX_SHADER);
^
main.cpp:88:59: error: ‘glShaderSource’ was not declared in this scope
glShaderSource(vertShader, 1, &vertShaderSource, 0);
^
main.cpp:89:35: error: ‘glCompileShader’ was not declared in this scope
glCompileShader(vertShader);
^
main.cpp:90:61: error: ‘glGetShaderiv’ was not declared in this scope
glGetShaderiv(vertShader, GL_COMPILE_STATUS, &status);
^
main.cpp:93:64: error: ‘glGetShaderInfoLog’ was not declared in this scope
glGetShaderInfoLog(vertShader, 512, 0, errorMessage);
^
main.cpp:106:64: error: ‘glGetShaderInfoLog’ was not declared in this scope
glGetShaderInfoLog(fragShader, 512, 0, errorMessage);
^
main.cpp:113:36: error: ‘glCreateProgram’ was not declared in this scope
program_ = glCreateProgram();
^
main.cpp:115:44: error: ‘glAttachShader’ was not declared in this scope
glAttachShader(program_, vertShader);
^
main.cpp:117:31: error: ‘glLinkProgram’ was not declared in this scope
glLinkProgram(program_);
^
main.cpp:118:57: error: ‘glGetProgramiv’ was not declared in this scope
glGetProgramiv(program_, GL_LINK_STATUS, &status);
^
main.cpp:120:63: error: ‘glGetProgramInfoLog’ was not declared in this scope
glGetProgramInfoLog(program_, 512, 0, errorMessage);
^
main.cpp:125:34: error: ‘glDeleteShader’ was not declared in this scope
glDeleteShader(vertShader);
^
main.cpp:129:65: error: ‘glGetUniformLocation’ was not declared in this scope
uniformMVP_ = glGetUniformLocation(program_, "mvpMatrix");
^
main.cpp: In member function ‘virtual bool gl_ifi::GlExample::render()’:
main.cpp:137:31: error: ‘glEnable’ was not declared in this scope
glEnable(GL_DEPTH_TEST);
^
main.cpp:138:31: error: ‘glDisable’ was not declared in this scope
glDisable(GL_CULL_FACE);
^
main.cpp:141:44: error: ‘glClearColor’ was not declared in this scope
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
^
main.cpp:142:58: error: ‘glClear’ was not declared in this scope
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
^
main.cpp:145:30: error: ‘glUseProgram’ was not declared in this scope
glUseProgram(program_);
^
main.cpp:149:71: error: ‘glUniformMatrix4fv’ was not declared in this scope
glUniformMatrix4fv(uniformMVP_, 1, GL_FALSE, &mvpMatrix_[0][0]);
^
main.cpp:151:52: error: ‘glBindVertexArray’ was not declared in this scope
glBindVertexArray(cube_->getVertexArrayId());
^
main.cpp:153:42: error: ‘glDrawElements’ was not declared in this scope
GL_UNSIGNED_INT, 0);
^
main.cpp: In member function ‘virtual bool gl_ifi::GlExample::end()’:
main.cpp:163:37: error: ‘glDeleteProgram’ was not declared in this scope
glDeleteProgram(program_);
^
Not declared in scope means you didn't include the header, or didn't include it properly. 未在范围中声明意味着您没有包括标头,或未正确包含标头。
#include <GL/glut.h>
Should give you everything. 应该给你一切。 If that doesn't work, try just gl.h. 如果这不起作用,请尝试gl.h。
Those "glXXX was not declared" means you don't include glew. 这些“未声明glXXX”表示您不包含glew。
Try something like #include "GLEW/include/GL/glew.h
The idea is that glew.h
must be included first. 尝试类似#include "GLEW/include/GL/glew.h
这样的想法。这个想法是必须首先包含glew.h
Glew is used to find glXXX functions for OpenGL > 1.3 Glew用于查找OpenGL> 1.3的glXXX函数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.