2

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?

Community
  • 1
  • 1
Edward J Brown
  • 333
  • 1
  • 5
  • 17
  • Possible duplicate of [Skipping Incompatible Libraries at compile](http://stackoverflow.com/questions/3119714/skipping-incompatible-libraries-at-compile) – Chris Beck Dec 01 '15 at 03:12
  • try to this: `dnf install freeglut-devel`. It is worked for me. – pezy Dec 02 '15 at 06:45

4 Answers4

2

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()
Oliv
  • 17,610
  • 1
  • 29
  • 72
  • I have looked to the GLFW site, since my last download of GLFW source it seems that building instructions have changed... So if my solution work for you, it might means that you have an old GLFW library. – Oliv Dec 02 '15 at 21:35
0

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`
Kamyar Infinity
  • 2,711
  • 1
  • 21
  • 32
0
  • Make sure ld cache updated

opengl@local:~/Development/Utilities$ sudo /sbin/ldconfig

  • Make sure ld see libraries

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(...

0

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.

Edward J Brown
  • 333
  • 1
  • 5
  • 17