Can't compile easy source in C++ and OpenGL (GLFW) in Linux in NetBeans
Solution 1:
First things first:
this is my source (I didn't use this characters: <, > in header files.):
That is wrong, and you should. Your current include statements are wrong, and I am actually surprised how it passed the compilation process this way.
You are seeing linker errors in here:
/home/jan/NetBeansProjects/a/main.cpp:12: undefined reference to `glfwInit'
/home/jan/NetBeansProjects/a/main.cpp:16: undefined reference to `glfwCreateWindow'
/home/jan/NetBeansProjects/a/main.cpp:19: undefined reference to `glfwTerminate'
/home/jan/NetBeansProjects/a/main.cpp:22: undefined reference to `glfwMakeContextCurrent'
/home/jan/NetBeansProjects/a/main.cpp:25: undefined reference to `glewExperimental'
/home/jan/NetBeansProjects/a/main.cpp:26: undefined reference to `glewInit'
There might be the following options for the failure:
You are not linking against the library (most likely)
You are not having the library installed (unlikely, based on your description)
You are using symbols not present in the library (again, unlikely)
The most probably reason is that you are not linking against the library, eventually. You should have this set up for the linker:
-lglfw3
Note that you will also need to add everything in the chain that comes up as a dependency when you start adding these, so based on your comment this is the whole chain to add:
-L/usr/local/lib -lglfw3 -pthread -lGLEW -lGLU -lGL -lrt -lXrandr -lXxf86vm -lXi -lXinerama -lX11
Since you are using the Netbeans IDE, you will need to go to the project settings to set it up unless you edit the files in the background manually. Here, you can see a screenshot which demonstrates that you have a linker tab where you can set up all this properly.
Solution 2:
I resolve it:
I added these parameters to linker:
-L/usr/local/lib -lglfw3 -pthread -lGLEW -lGLU -lGL -lrt -lXrandr -lXxf86vm -lXi -lXinerama -lX11