Error to compile Opengl code

Asked

Viewed 314 times

0

Good Afternoon, I use linux and I’m learning OpenGL, but when I go compile my code for that mistake:

/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

the only code I have is this:

#include <iostream>
#include <GL/glew.h>

and the code I used to compile was this: g++ main.cpp -o main

I already installed the libs:libglm-dev and libglew-dev.

How could I solve.
Use linux Mint 19.3

1 answer

0


Missing put Linker options in gcc:

g++ main.cpp -o main -lGLEW

And also define a function int main()

For a complete project you will also need to link at least Opengl with -lGL.

  • Thank you very much, sorry I didn’t answer before, I had a few problems here, I didn’t know I needed the main method to compile, thanks

  • To compile an executable with the option -o have to define int main(). Only when you build an Object file from an eventual dependency you don’t need.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.