c++ - OpenGL with GLFW and GLEW - compiling with gcc on windows -


i'm trying run opengl program uses glfw , glew libraries built myself. starter code use is

#include <iostream>  // glew #define glew_static #include <glew.h>  // glfw #include <glfw3.h>   // function prototypes void key_callback(glfwwindow* window, int key, int scancode, int action, int mode);  // window dimensions const gluint width = 800, height = 600;  // main function, here start application , run game loop int main() {     std::cout << "starting glfw context, opengl 3.3" << std::endl;     // init glfw     glfwinit();     // set required options glfw     glfwwindowhint(glfw_context_version_major, 3);     glfwwindowhint(glfw_context_version_minor, 3);     glfwwindowhint(glfw_opengl_profile, glfw_opengl_core_profile);     glfwwindowhint(glfw_resizable, gl_false);      // create glfwwindow object can use glfw's functions     glfwwindow* window = glfwcreatewindow(width, height, "learnopengl", 0, 0);     glfwmakecontextcurrent(window);     if (window == null)     {         std::cout << "failed create glfw window" << std::endl;         glfwterminate();         return -1;     }      // set required callback functions     glfwsetkeycallback(window, key_callback);      // set true glew knows use modern approach retrieving function pointers , extensions     glewexperimental = gl_true;     // initialize glew setup opengl function pointers     if (glewinit() != glew_ok)     {         std::cout << "failed initialize glew" << std::endl;         return -1;     }          // define viewport dimensions     glviewport(0, 0, width, height);      // game loop     while (!glfwwindowshouldclose(window))     {         // check if events have been activated (key pressed, mouse moved etc.) , call corresponding response functions         glfwpollevents();          // render         // clear colorbuffer         glclearcolor(0.2f, 0.3f, 0.3f, 1.0f);         glclear(gl_color_buffer_bit);          // swap screen buffers         glfwswapbuffers(window);     }      // terminate glfw, clearing resources allocated glfw.     glfwterminate();     return 0; }  // called whenever key pressed/released via glfw void key_callback(glfwwindow* window, int key, int scancode, int action, int mode) {     std::cout << key << std::endl;     if (key == glfw_key_escape && action == glfw_press)         glfwsetwindowshouldclose(window, gl_true); } 

then type

g++ -i<path headers> tma.cpp -l<path libraries> -lglu32 -lopengl32 -lglfw3 -lglew32 

which yields number of 'undefined reference to' errors.

the code should ok, run in visual studio.

this command:

g++ -i<path headers> tma.cpp -l<path libraries> -lglu32 -lopengl32 -lglfw3 -lglew32

will not enough in windows. need link additional system libraries. example, every project in visual studio 2012 have these attached default:

kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib 

that why compiled fine in vs.

kernel32.lib , user32.lib should linked. gdi32.lib required, when graphic operations.

first solution:

link these libraries manually:

g++ -i<path headers> tma.cpp -l<path libraries> -lglu32 -lopengl32 -lglfw3 -lglew32 -lkernel32 -luser32 -lgdi32 -lws2_32

if remember correctly, ws2_32.a name of winsock2 library supplied mingw.

second solution:

if use mingw, can use -mwindows flag:

g++ -i<path headers> tma.cpp -l<path libraries> -lglu32 -lopengl32 -lglfw3 -lglew32 -mwindows

this link, among few others, gdi32.a, kernel32.a, user32.a , ws2_32.a.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -