Compilation problems in OpenGL code with g ++

When I try to compile opengl code written in c using gcc with the following commands, it works fine:

gcc -Wall tutorial10.c -lGL -lglut -lGLU

But when I try to do the same compilation with g ++

g++ -Wall tutorial10.c -lGL -lglut -lGLU

He begins to give a lot of mistakes like this:

tutorial10.c: In functionvoid drawRect()’:
tutorial10.c:28:34: error: ‘glClearBufferfvwas not declared in this scope
tutorial10.c:34:28: error: ‘glUseProgramwas not declared in this scope
tutorial10.c:36:24: error: ‘glGenBufferswas not declared in this scope
tutorial10.c:37:37: error: ‘glBindBufferwas not declared in this scope
tutorial10.c:47:71: error: ‘glBufferDatawas not declared in this scope
tutorial10.c:49:52: error: ‘glVertexAttribPointerwas not declared in this scope
tutorial10.c:50:29: error: ‘glEnableVertexAttribArraywas not declared in this scope
tutorial10.c:52:60: error: ‘glGetUniformLocationwas not declared in this scope
tutorial10.c:54:42: error: ‘glUniform4fwas not declared in this scope
tutorial10.c:59:30: error: ‘glDisableVertexAttribArraywas not declared in this scope
tutorial10.c: In functionint main(int, char**)’:
tutorial10.c:93:34: error: ‘glCreateProgramwas not declared in this scope
tutorial10.c:95:54: error: ‘glCreateShaderwas not declared in this scope
tutorial10.c:124:76: error: ‘glShaderSourcewas not declared in this scope
tutorial10.c:128:36: error: ‘glCompileShaderwas not declared in this scope
tutorial10.c:134:49: error: ‘glAttachShaderwas not declared in this scope
tutorial10.c:136:29: error: ‘glLinkProgramwas not declared in this scope
tutorial10.c:147:35: error: ‘glDeleteShaderwas not declared in this scope

Comment headers:

#include<stdio.h>
#include<stdlib.h>
#include<GL/glut.h>
#include<malloc.h>
#include<string.h>
#include<math.h>
+4
source share
1 answer

You do not have opengl function declarations inside your translation unit (most likely you did not include it <GL/gl.h>).

gcc , C - , , gcc . , - , . float, .

, -Wimplicit-function-declaration ( -Wall, , ).

g++, , ++, .

, , , ( ).

+4

Source: https://habr.com/ru/post/1541422/


All Articles