What opengl library should i use with an nvidia graphics card - c++

I'm trying to compile an SDL2 and OpenGL game on linux, but the error that shows up is always
/usr/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status
Which led me to find out which opengl version I have. But it shows this:
OpenGL version string: 4.5.0 NVIDIA 375.39
But I don't know which parameter or library to use with nvidia opengl.
Does anyone know?

Fixed it easily by just swapping out -lGL with -l:libGL.so.1.
But find out what library you have using
ls /usr/lib/
and then look for libGL.so.version_number_here
Works for me until I need to add it to my linker.

Related

Can't get openGL to link in ubuntu

This is my first question on stackoverflow. I've seen a few posts related to openGL on Ubuntu, but none seem to relate to the problem I'm having.
For some reason whenever I try to build my project in eclipse-CDT I get the following console output:
**** Build of configuration Debug for project windows ****
make all
Building file: ../src/windows.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/windows.d" -MT"src/windows.d" -o "src/windows.o" "../src/windows.cpp"
Finished building: ../src/windows.cpp
Building target: windows
Invoking: GCC C++ Linker
g++ -o "windows" ./src/OGdisplay.o ./src/windows.o -lGLEW -lGL -lSDL2
/usr/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status
makefile:45: recipe for target 'windows' failed
make: *** [windows] Error 1
**** Build Finished ****
I've installed the mesa-common-Dev package and all the others I could find that have to do with opengl development, but it won't budge. I put: GLEW, GL, and SDL2 in libraries under the GCC C++ linker settings. It doesn't seem to have any issues finding SDL2 and GLEW, but for some reason just can't find GL.
I went to usr/include and can clearly see the GL folder with it's contents as well as SDL2(which it has no issues finding). I've tried the same thing in codeblocks with extremely simple code and get the same result saying it can't find GL.
I'm running Ubuntu 16.04LTS with an nvidia GeForce GTX 1060. I'm also using the NVIDIA Xserver driver version 367.44. Under the nvidia Xserver settings in the OpenGL information sections it says it has version: 4.5.0 NVIDIA 367.44 if that helps. If you need anymore information just let me know, I'm almost certain that it's something simple I'm not thinking of.
Here are my CDT linker settings if it'll let me post a pick:
linker settings screenshot
SOLUTION: I'm not sure it's much of a solution, but I reinstalled NVIDIA X server and it seems to be working fine now. Not sure what was orginally causing it though.

Trying to link library to a file which uses OpenGL and linker not being able to find GL relevant file

So this is my output when i run
$ g++ main.c -lGL
/usr/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status
however i DO have GL installed because it came with my graphics card driver which i downloaded from nvidia website namely the 346.72 for my graphics card 780ti
when i do a search i.e locate GL here is part of the response
...
/usr/include/GL
/usr/include/GL/freeglut.h
/usr/include/GL/freeglut_ext.h
/usr/include/GL/freeglut_std.h
/usr/include/GL/gl.h
/usr/include/GL/gl_mangle.h
/usr/include/GL/glcorearb.h
/usr/include/GL/glew.h
/usr/include/GL/glext.h
/usr/include/GL/glu.h
/usr/include/GL/glu_mangle.h
/usr/include/GL/glut.h
/usr/include/GL/glx.h
/usr/include/GL/glx_mangle.h
/usr/include/GL/glxew.h
/usr/include/GL/glxext.h
/usr/include/GL/glxint.h
/usr/include/GL/glxmd.h
/usr/include/GL/glxproto.h
/usr/include/GL/glxtokens.h
/usr/include/GL/internal
/usr/include/GL/wglew.h
/usr/include/GL/internal/dri_interface.h
/usr/include/GL/internal/glcore.h
...
/usr/lib/x86_64-linux-gnu/libEGL.so
/usr/lib/x86_64-linux-gnu/libEGL.so.1
/usr/lib/x86_64-linux-gnu/libEGL.so.346.72
/usr/lib/x86_64-linux-gnu/libGL.la
/usr/lib/x86_64-linux-gnu/libGL.so
/usr/lib/x86_64-linux-gnu/libGL.so.1
/usr/lib/x86_64-linux-gnu/libGL.so.346.72
/usr/lib/x86_64-linux-gnu/libGLESv1_CM.so
/usr/lib/x86_64-linux-gnu/libGLESv1_CM.so.1
/usr/lib/x86_64-linux-gnu/libGLESv1_CM.so.346.72
/usr/lib/x86_64-linux-gnu/libGLESv2.so
/usr/lib/x86_64-linux-gnu/libGLESv2.so.2
/usr/lib/x86_64-linux-gnu/libGLESv2.so.346.72
/usr/lib/x86_64-linux-gnu/libGLEW.so
/usr/lib/x86_64-linux-gnu/libGLEW.so.1.10
/usr/lib/x86_64-linux-gnu/libGLEW.so.1.10.0
/usr/lib/x86_64-linux-gnu/libGLU.a
/usr/lib/x86_64-linux-gnu/libGLU.so
/usr/lib/x86_64-linux-gnu/libGLU.so.1
/usr/lib/x86_64-linux-gnu/libGLU.so.1.3.1
/usr/lib/x86_64-linux-gnu/libQt5OpenGL.so.5
/usr/lib/x86_64-linux-gnu/libQt5OpenGL.so.5.2
/usr/lib/x86_64-linux-gnu/libQt5OpenGL.so.5.2.1
/usr/lib/x86_64-linux-gnu/libQtOpenGL.so.4
/usr/lib/x86_64-linux-gnu/libQtOpenGL.so.4.8
/usr/lib/x86_64-linux-gnu/libQtOpenGL.so.4.8.6
/usr/lib/x86_64-linux-gnu/mesa/libGL.so
....
which shows that it does exist
how do i link this with the linker?
The canonical way is to add the directory containing architecture-plattform specific libraries, like /usr/lib/x86_64-linux-gnu/ to the system linker path. To do this add it to /etc/ld.so.conf and rebuild the linker cache. Rebuilding the linker cache is done by executing ldconfig with superuser privileges.

Linking compute shader

I try to compile this small example and I have this error executing the make:
g++ -o ogl_cs_example main.cpp opengl_cs.cpp opengl_util.cpp -Wall -Iinclude -lX11 -lGL -lGLU
/tmp/ccFLIOt2.o: In function `updateTex(int)':
main.cpp:(.text+0xc6): undefined reference to `glDispatchCompute'
/tmp/ccQ8pShN.o: In function `genTexture()':
opengl_util.cpp:(.text+0x3df): undefined reference to `glBindImageTexture'
/tmp/ccQ8pShN.o: In function `initGL()':
opengl_util.cpp:(.text+0x7dd): undefined reference to `glXCreateContextAttribsARB'
collect2: error: ld returned 1 exit status
make: *** [example] Error 1
What am I missing?
Those functions are all OpenGL / GLX extensions that are not provided by your platform's minimal implementation.
You have to load them at run-time using glXGetProcAddress (...), they are not contained in any library that you link directly to. Though you can link to an extension managing library such as GLEW to do the dirty work for you, you will still have to do more than merely add a new linking dependency.
You generally have to initialize said libraries after you create your OpenGL render context. It is worth pointing out that one thing that sets WGL (Windows) and GLX (X11) apart is that you do not have to create a GL context before you can load extensions with GLX, so you can actually load glXCreateContextAttribsARB, glDispatchCompute and glBindImageTexture before you have a context. Whether the later two function pointers you get will do anything at run-time is a different story, however, and depends on the capabilities of the context you created.
You are forgetting to link something. If you are using GLEW, make sure you are linking to glew32.lib (or libglew32.a or whatever for your system).
undefined reference means you did not LINK to the libraries

GCC - Linking bass.lib on Ubuntu

I wrote an application on Windows using CPP and BASS, and now I have to get it running on Linux (UBUNTU).
I am using gcc version 4.5.2.
I have bass.lib in my directory from which I try to compile prog.cpp using the following command arguments:
gcc prog.cpp -L. -lbass.lib
But I get the following error:
/usr/bin/ld: cannot find -lbass.lib
collect2: ld returned 1 exit status
I figure that this is a linking error, the compiler is not finding Bass.lib but I have specified as an argument on the command line.
Not sure what to do, any help would be really great.
bass.lib sounds like the windows library. You cannot use libraries generated on windows, (likely generated with the MSVC compiler), on linux.
The linux version of the library seems to be named libbass.so , in which case you'd use -lbass as the linker argument , and possibly other compiler/linker flags as well depending on where on the system you install the library. The bass.txt in the linux download of libbass have a few notes on what to do on Linux.

Help solving a error in openGL

I am making a group work in openGL, and when i try to open the file that my partner gave me i have this error:
-------------- Build: Debug in CG ---------------
Linking console executable: bin/Debug/CG
ld: library not found for -lGL
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
I've seen the same code working in his computer.
Is it cause he is working in Windows? and i am working in MacOSX? I am using CodeBlocks IDE.
Can anyone help me solving this?
The OpenGL library is actually a Framework on MacOSX.
It should link correctly if you replace -lGL by -framework OpenGL.
Try something like the below, as jweyrich said, OpenGL is a framework in Mac OS X:
gcc -framework OpenGL -framework GLUT -o test test.c
Check that you have the actual library, and that -lGL is the correct flag. The name of the library may be different on your system.