0

I am currently developing a little program, and faced an issue when I tried to run it on a clean Linux distribution: OpenGL freeglut3 was not installed by default. I faced the same issue when I compiled it for windows.

To circumvent this issue, I looked to static linking the libraries, kind-of embedding them into the executable. The full command I used is g++ thing.cpp -Wall -o thing -static -lGL -lglut -static-libgcc -static-libstdc++.

little edit: compiling it without -static just works, but only statically includes libgcc and libstdc++

The error message I got is:

coolperson@iogamesplayer:~/c++/text/program$ g++ thing.cpp -o thing -static -lGL -lglut -static-libgcc -static-libstdc++
/usr/bin/ld: cannot find -lGL: No such file or directory
collect2: error: ld returned 1 exit status
coolperson@iogamesplayer:~/c++/thing/program$ 

I can compile it normally, and I have statically linked the default libraries by using g++ thing.cpp -o thing -static-libgcc -static-libstdc++.

What I tried is using my own compiled freeglut 3.4.0, that didn't work. I couldn't find anything online.

I tried asking Reddit, but reddit being reddit didn't exactly tell me what I was doing wrong, and how to statically link it :P.

Tell me what I'm doing wrong, and how I can statically link openGL glut.h.

5
  • 4
    Statically linking with libGL is a very weird thing to do, as every system has its own libGL that is very tightly tied to the graphics driver. Many applications use an OpenGL loader (like GLAD or GLEW) instead to query the required OpenGL functions at runtime. That just leaves glut, for which you need a static library to link with, not a .dll or .so. Commented Dec 14, 2023 at 10:05
  • @Botje, so should I use GLEW, or can I add gl.h and glut.h to the project dir and include that Commented Dec 14, 2023 at 10:25
  • 1
    You should use GLEW or gl.h, not both. There seems to be some confusion on your part on the role of header files: they just contain type definitions and function signatures, not actual code. The code is supposed to be provided at link time (as you do with the -l flag). I'm not sure if glut can interopate with GLEW though... Honestly I would forget about GLUT, it is old and unmaintained. Commented Dec 14, 2023 at 10:28
  • 1
    @Botje: GLUT can interoperate with GLEW fine, just call glewInit() after glutCreateWindow(). Commented Dec 14, 2023 at 14:50
  • There are no static GL libraries on your system (probably for a reason). Commented Dec 14, 2023 at 16:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.