Reputation: 331
So I am fairly new to linux and trying to compile an openGL project which uses GLEW and GLFW in CodeBlocks with GCC++.
As shown below I have my linker flags set to -lglfw -lGLEW -lGL and have tried various permutations involving different orders with and without -lGLU.
These all result in the linker error
cannot find -lGL
or the full build log
g++ -L/usr/lib64 -L/usr/lib -o Voxel .objs/Block.o ... other object files ... .objs/World.o -lglfw -lGLEW -lGL
/usr/bin/ld: skipping incompatible /usr/lib/libGL.so when searching for -lGL
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/5.1.1/../../../libGL.so when searching for -lGL
/usr/bin/ld: skipping incompatible /lib/libGL.so when searching for -lGL
/usr/bin/ld: skipping incompatible /usr/lib/libGL.so when searching for -lGL
/usr/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status
I found this similar question (and many other forums) and attempted the suggested actions which seem to hint at either a different order of flags and/or a bad symlink (which I don't know how to/if I need to remove and re add).
The command below confirms I have libGL installed already.
dnf install libGL
I have also tried
dnf install mesa-*
and installed some extra packages, to no avail.
Performing
locate libGL
gives me the following
/usr/lib/libGL.la
/usr/lib/libGL.so
/usr/lib/libGL.so.1
/usr/lib/libGL.so.1.2.0
/usr/lib/libGL.so.358.16
/usr/lib/libGLESv1_CM.so
/usr/lib/libGLESv1_CM.so.1
/usr/lib/libGLESv1_CM.so.358.16
/usr/lib/libGLESv2.so
/usr/lib/libGLESv2.so.2
/usr/lib/libGLESv2.so.358.16
/usr/lib/libGLdispatch.so.0
/usr/lib64/libGL.la
/usr/lib64/libGL.so
/usr/lib64/libGL.so.1
/usr/lib64/libGL.so.358.16
/usr/lib64/libGLESv1_CM.so
/usr/lib64/libGLESv1_CM.so.1
/usr/lib64/libGLESv1_CM.so.358.16
/usr/lib64/libGLESv2.so
/usr/lib64/libGLESv2.so.2
/usr/lib64/libGLESv2.so.358.16
/usr/lib64/libGLEW.so
/usr/lib64/libGLEW.so.1.10
/usr/lib64/libGLEW.so.1.10.0
/usr/lib64/libGLEWmx.so
/usr/lib64/libGLEWmx.so.1.10
/usr/lib64/libGLEWmx.so.1.10.0
/usr/lib64/libGLU.so
/usr/lib64/libGLU.so.1
/usr/lib64/libGLU.so.1.3.1
/usr/lib64/libGLdispatch.so.0
/usr/share/doc/libGLEW
/usr/share/doc/libGLEWmx
/usr/share/doc/libGLEW/LICENSE.txt
/usr/share/doc/libGLEWmx/LICENSE.txt
/usr/share/licenses/mesa-libGL
/usr/share/licenses/mesa-libGLES
/usr/share/licenses/mesa-libGL/COPYING
/usr/share/licenses/mesa-libGLES/COPYING
/var/cache/PackageKit/metadata/updates/packages/mesa-libGL-11.0.6-1.20151122.fc23.x86_64.rpm
/var/cache/PackageKit/metadata/updates/packages/mesa-libGLES-11.0.6-1.20151122.fc23.x86_64.rpm
I am running Fedora 23 and have an nVidia GeForce GTX 750Ti with the proprietary nVidia drivers installed.
In short how do I link OpenGL, GLFW and GLEW with GCC++ on Linux?
Upvotes: 2
Views: 6738
Reputation: 331
Rather than doing a find which does not colour its output I did a directory listing inside the lib64 folder and found that there were 3 files for libGL one of which was an odd colour compared to the others in the folder.
(Turquoise - symlink) lib64.so.1 (Green - file) libGL.so.Version (Red on Black - orphaned symlink) libGL.so
At this point I familiarised myself with the basics of the ln command and set the symlink to point to libGL.so using
ln -s libGL.so.Version libGL.so
This resolved the issue.
Upvotes: 0
Reputation: 18081
On linux you should link to dl. I have never used -lGL... but I have also never used GLEW. You may just need to replace -lGL by -ldl.
Here's few lines of cmake script I use to compile application using GLFW (without GLEW) on both linux and windows:
target_link_libraries(myopengl_target glfw ${GLFW_LIBRARIES})
if (${WIN32})
find_library(OPENGL32_LIBRARY opengl32)
target_link_libraries(myopengl_target opengl32 ${OPENGL32_LIBRARIES})
elseif(${UNIX})
target_link_libraries(myopengl_target dl)
endif()
Upvotes: 2
Reputation: 11
opengl@local:~/Development/Utilities$ sudo /sbin/ldconfig
opengl@local:~/Development/Utilities$ /sbin/ldconfig -p | sort -u | egrep --color='auto' 'lib(gl|GL)' libglapi.so.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libglapi.so.0 libGLESv2.so.2 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libGLESv2.so.2 libGLESv2.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libGLESv2.so libGLEW.so.1.10 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libGLEW.so.1.10 libglib-2.0.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libglib-2.0.so.0 libglib-2.0.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libglib-2.0.so libglibmm-2.4.so.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libglibmm-2.4.so.1 libglibmm_generate_extra_defs-2.4.so.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libglibmm_generate_extra_defs-2.4.so.1 libGL.so.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libGL.so.1 libGL.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libGL.so libGLU.so.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libGLU.so.1 libGLU.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libGLU.so libglut.so.3 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libglut.so.3 libglut.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libglut.so
Link as always using -L && -l flags
You can also try to simplify development process by use cmake:
add_exacutable(... find_library(... target_link_libraries(...
Upvotes: 0
Reputation: 2759
If you have pkg-config
, you may try with that as well. It provides the appropriate addresses itself:
`pkg-config --cflags glfw3` -o myprog myprog.c `pkg-config --libs glfw3`
Upvotes: 0