OpenGL / glut / stdC ++ build errors

I use Ubuntu and try to use synaptic to install everything that contained the word "GLUT" in it, as well as SDL and opengl. But still, a simple program will not compile. He shows it:

 opengl1.cpp :(. text + 0xe): undefined reference to `glBegin 'opengl1.cpp :(. text + 0x2e): undefined reference to` glVertex2i 'opengl1.cpp :(. text + 0x33): undefined reference to `glFlush' /tmp/ccnwQeLu.o: In function` MyInit () ': opengl1.cpp :(. text + 0x4c): undefined reference to `glGetString 'opengl1.cpp :(. text + 0x57): undefined reference to` std :: cout' opengl1.cpp :(. text + 0x5c): undefined reference to `std :: basic_ostream> & std :: operator> (std :: basic_ostream> &, unsigned char const *) 'opengl1.cpp :(. text + 0x6c): undefined reference to` std :: basic_ostream> & std: : operator> (std :: basic_ostream> &, char const *) 'opengl1.cpp :(. text + 0x78): undefined reference to `glGetString' opengl1.cpp :(. text + 0x83): undefined reference to` std: : cout 'opengl1.cpp :(. text + 0x88): undefined reference to `std :: basic_ostream> & std :: operator> (std :: basic_ostream> &, unsigned char const *)' opengl1.cpp :(. text + 0x98  ): undefined reference to `std :: basic_ostream> & std :: operator> (std :: basic_ostream> &, char const *) 'opengl1.cpp :(. text + 0xc0): undefined reference to` glClearColor' opengl1.cpp :(. text + 0xdf): undefined reference to `glPointSize 'opengl1.cpp :(. text + 0xf8): undefined reference to` glMatrixMode' opengl1. cpp :(. text + 0xfd): undefined reference to `glLoadIdentity 'opengl1.cpp :(. text + 0x12d): undefined reference to` gluOrtho2D' /tmp/ccnwQeLu.o: In function `main ': opengl1.cpp :( .text + 0x14a): undefined reference to `glutInit 'opengl1.cpp :(. text + 0x156): undefined reference to` glutInitDisplayMode' opengl1.cpp :(. text + 0x16d): undefined reference to `glutInitWindowSize 'opengl1.cpp: (.text + 0x181): undefined reference to `glutInitWindowPosition 'opengl1.cpp :(. text + 0x18d): undefined reference to` glutCreateWindow' opengl1.cpp :(. text + 0x19e): undefined reference to `glutDisplayFunc 'opengl1.cpp :(. text + 0x1a3): undefined reference to `glutMainLoop '  /tmp/ccnwQeLu.o: In function `__static_initialization_and_destruction_0 (int, int) ': opengl1.cpp :(. text + 0x1cb): undefined reference to` std :: ios_base :: Init :: Init ()' opengl1.cpp: (.text + 0x1d0): undefined reference to `__gxx_personality_v0 'collect2: ld returned 1``std :: ios_base :: Init :: ~ Init ()' /tmp/ccnwQeLu.o:(.eh_frame+0x12) exit status 

If I use g ++ instead of gcc, I get the following:

  vim opebgl1.cpp
 g ++ opengl1.cpp -o opengl1 -lGL -lstdc ++ -lc -lm
  and then get this:
 /tmp/ccCJBuIl.o: In function `MyInit () ':
 opengl1.cpp :(. text + 0x12d): undefined reference to `gluOrtho2D '
 /tmp/ccCJBuIl.o: In function `main ':
 opengl1.cpp :(. text + 0x14a): undefined reference to `glutInit '
 opengl1.cpp :(. text + 0x156): undefined reference to `glutInitDisplayMode '
 opengl1.cpp :(. text + 0x16d): undefined reference to `glutInitWindowSize '
 opengl1.cpp :(. text + 0x181): undefined reference to `glutInitWindowPosition '
 opengl1.cpp :(. text + 0x18d): undefined reference to `glutCreateWindow '
 opengl1.cpp :(. text + 0x19e): undefined reference to `glutDisplayFunc '
 opengl1.cpp :(. text + 0x1a3): undefined reference to `glutMainLoop '
 collect2: ld returned 1 exit status

So what do I really need to get started with opengl in Ubuntu?

+4
source share
4 answers

Add "-lstdC ++ -lGL" to your linker flags. Or try compiling it like this:

g++ opengl1.cpp -o opengl1 -lGL -lGLU -lc -lm 

(edit: added -lGLU, removed -lstd ++)

+7
source

You should also associate it with abundance and GLU:

 g++ opengl1.cpp -o opengl1 -lGL -lstdc++ -lc -lm -lglut -lGLU 

Files ending with .cpp must be compiled with g ++ . The remaining errors are related to the binding process, and they should not occur if you create the application using the command suggested above. If they do, be sure to install libglut and libglu.

+3
source

Make sure you use g++ to create your C ++ files to avoid linker errors related to the C ++ standard library.

To enable GLUT characters, you just need to add -lglut to your final build command.

+2
source

When compiling the code, you must specify some parameters according to your inclusions. You have already used -lGL , -lm , etc. To use gluOrtho2D use the -lGLU option -lGLU and for other functions starting with glut , use -lglut

0
source

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


All Articles