c++ - Using MinGW to compile OpenGL and getting glut Linker errors -
i have program worked on computer before wiped hard drive , reinstalled operating system. reinstalled necessary compilers , dlls im getting linker errors glut. below snippet of code trying run , compile command is.
here main trying run:
/* * gl01hello.cpp: test opengl c/c++ setup */ #include <windows.h> // ms windows #include <gl/freeglut.h> // glut, includes glu.h , gl.h /* handler window-repaint event. call when window first appears , whenever window needs re-painted. */ void display() { glclearcolor(0.0f, 0.0f, 0.0f, 1.0f); // set background color black , opaque glclear(gl_color_buffer_bit); // clear color buffer // draw red 1x1 square centered @ origin glbegin(gl_quads); // each set of 4 vertices form quad glcolor3f(1.0f, 0.0f, 0.0f); // red glvertex2f(-0.5f, -0.5f); // x, y glvertex2f( 0.5f, -0.5f); glvertex2f( 0.5f, 0.5f); glvertex2f(-0.5f, 0.5f); glend(); glflush(); // render } /* main function: glut runs console application starting @ main() */ int main(int argc, char** argv) { glutinit(&argc, argv); // initialize glut glutcreatewindow("opengl setup test"); // create window given title glutinitwindowsize(320, 320); // set window's initial width & height glutinitwindowposition(50, 50); // position window's initial top-left corner glutdisplayfunc(display); // register display callback handler window re-paint glutmainloop(); // enter infinitely event-processing loop return 0; }
and here command being run:
g++ gl01hello.cpp -o gl01hello.exe -lglu32 -lopengl32 -lfreeglut
and errors getting below:
g++ gl01hello.cpp -o gl01hello.exe -lglu32 -lopengl32 -lfreeglut c:\users\daniel\appdata\local\temp\ccc01ype.o:gl01hello.cpp:(.text+0x1c): undefined reference `_imp____glutinitwithexit@12' c:\users\daniel\appdata\local\temp\ccc01ype.o:gl01hello.cpp:(.text+0x3e): undefined reference `_imp____glutcreatewindowwithexit@8' c:\users\daniel\appdata\local\temp\ccc01ype.o:gl01hello.cpp:(.text+0x60): undefined reference `_imp____glutcreatemenuwithexit@8' c:\users\daniel\appdata\local\temp\ccc01ype.o:gl01hello.cpp:(.text+0x198): undefined reference `_imp__glutinitwindowsize@8' c:\users\daniel\appdata\local\temp\ccc01ype.o:gl01hello.cpp:(.text+0x1b1): undefined reference `_imp__glutinitwindowposition@8' c:\users\daniel\appdata\local\temp\ccc01ype.o:gl01hello.cpp:(.text+0x1c2): undefined reference `_imp__glutdisplayfunc@4' c:\users\daniel\appdata\local\temp\ccc01ype.o:gl01hello.cpp:(.text+0x1cc): c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: c:\users\daniel\appdata\local\temp\ccc01ype.o: bad reloc address 0x20 in section `.eh_frame' c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: invalid operation collect2.exe: error: ld returned 1 exit status makefile:2: recipe target 'all' failed make: *** [all] error 1
any in resolving these linker errors extremely helpful.
edit: edited code above simple example, , still getting similar linker error. reported similar problem generic "what causes linker errors" post , have tried many of , none of them have helped. thank fo attempt though
well, looks right. best bet is, build of freeglut you're using (specifically .def
, .lib
linker stubs) don't match (possibly .dll
). suggestion be, build freeglut sources using same compiler you're using build program. try that, , report on differences.
Comments
Post a Comment