Help me linking OpenGl using g++


#include <glew.h>


int main(){

    return 0;
}

I’m trying to compile this .cpp file with g++.

this is what I did.

g++ -std=c++11 main.cpp -I/include/GL

but I’m getting an error that says “no such file: glew.h”.

How do you guys compile OpenGL with g++? thanks.

[QUOTE=yj1214;1265135]


#include <glew.h>

int main(){
    return 0;
}

g++ -std=c++11 main.cpp -I/include/GL

but I’m getting an error that says “no such file: glew.h”. How do you guys compile OpenGL with g++? thanks.[/QUOTE]

You’re doing it right. The issue is probably that your system doesn’t have the GLEW header files installed. Typically, headers are in a “*-devel” package.

For example, GLEW headers would be in a separate “glew-devel” package, where as the glew library itself is in the “glew” package. Here:


> ls /usr/include/GL/glew.h
/usr/include/GL/glew.h

> rpm -qf /usr/include/GL/glew.h
glew-devel-1.9.0-5.1.2.x86_64

I’m sorry but I don’t know what you’re talking about. In my directory, I have these.


include
lib
glew32.dll
SDL2.dll
main.cpp

My glew.h is in the include folder. So I can type g++ -I/include/GL

or do I have to do something else?

I’m sorry but I don’t know what -DEVEL is. In my directory, I have these.


include
lib
glew32.dll
SDL2.dll
main.cpp

My glew.h is in the include folder. So I can type g++ -I/include/GL

or do I have to do something else?

try -I./include/GL (notice the “.” before the first “/”)

Right. Or -Iinclude/GL. You may also need to change #include <glew.h> to #include “glew.h” as well. <> means to look in the system include directories, and “” means to look in user-specified directories (basically), though the <> is up to the compiler.

Typically headers like glew.h would be installed system-wide in system include directories, so you’d use <>. But you’re not doing that.