1

EDIT:
After a bit more digging I have found that I have a libGL.so at /usr/lib/i386-linux-gnu/libGL.so and if I move this away then linking works correctly again. After looking at the error line for a while I thought that the full path to libGL.so in the message was suspicious because it would have been looking at multiple locations to find it and usually it only shows the name of the library not one specific full path. So the question now is; why did finding the other version cause the search to stop and show a confusing error message? (I'm the i386ness made it incompatible in some way).

ORIG:
For some reason I am having trouble linking in libGL.so into my application. The issue seems to be that ld (or gold in this case) is not looking in /usr/lib (which from everything I can find is one of the default locations) when trying to find it instead it is looking in a bit of a whacky location e.g.

/usr/bin/ld: error: cannot open /usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu/libGL.so: No such file or directory

Now /usr/lib/libGL.so definitely exists and I if I do an explicit -L/usr/lib in the makefile everything links correctly.

I'm wondering does anyone know what is going on here?

Info:
Ubuntu linux 12.10 x86
g++ 4.7
GNU gold linker
CPU AMD Phenom 2 x6
uname -m out: i686

EDIT: Output of link with -v parameter:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.7/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.2-2ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1) 
COMPILER_PATH=/usr/lib/gcc/i686-linux-gnu/4.7/:/usr/lib/gcc/i686-linux-gnu/4.7/:/usr/lib/gcc/i686-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.7/:/usr/lib/gcc/i686-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/i686-linux-gnu/4.7/:/usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.7/../../../../lib/:/lib/i386-linux-gnu/:/lib/../lib/:/usr/lib/i386-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/i686-linux-gnu/4.7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-o' 'application' '-v' '-L/home/user/src/tutorials/application/builds/./vendor/ogre3d/./lib' '-shared-libgcc' '-mtune=generic' '-march=i686'
 /usr/lib/gcc/i686-linux-gnu/4.7/collect2 --sysroot=/ --build-id --no-add-needed --as-needed --eh-frame-hdr -m elf_i386 --hash-style=gnu -dynamic-linker /lib/ld-linux.so.2 -z relro -o application /usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu/crt1.o /usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu/crti.o /usr/lib/gcc/i686-linux-gnu/4.7/crtbegin.o -L/home/user/src/tutorials/application/builds/./vendor/ogre3d/./lib -L/usr/lib/gcc/i686-linux-gnu/4.7 -L/usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu -L/usr/lib/gcc/i686-linux-gnu/4.7/../../../../lib -L/lib/i386-linux-gnu -L/lib/../lib -L/usr/lib/i386-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/i686-linux-gnu/4.7/../../.. /home/user/src/tutorials/application/builds/./src/most_basic_main.o /home/user/src/tutorials/application/builds/./src/QOgreWidget.o /home/user/src/tutorials/application/builds/./src/QtOgreApplication.o /home/user/src/tutorials/application/builds/./src/qt_gen/QtOgreApplication.moc.o /home/user/src/tutorials/application/builds/./src/qt_gen/QOgreWidget.moc.o -lpthread -lQtCore -lQtNetwork -lQtGui -lQtOpenGL -lRenderSystem_GLStatic -lOgreMainStatic -ldl -lfreetype -lXrandr -lGL -lGLU -lxcb -lX11 -lXext -lXpm -lXaw7 -lXt -lzzip -lfreeimage -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/i686-linux-gnu/4.7/crtend.o /usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu/crtn.o
/usr/bin/ld: error: cannot open /usr/lib/gcc/i686-linux-gnu/4.7/../../../i386-linux-gnu/libGL.so: No such file or directory
radman
  • 17,675
  • 11
  • 42
  • 58
  • Show the command line where you link? And the messages if you add -v to it? – Marc Glisse Jan 22 '13 at 08:36
  • What's the CPU architecture? x86 or x86-64? You can check that by running `uname -m`. – IneQuation Jan 22 '13 at 08:45
  • updated main description with details – radman Jan 22 '13 at 09:05
  • Your log output clearly states that the environment library `LIBRARY_PATH` doesn't include `/usr/lib`. I'm not sure what sets it, but that should point you where to look. – IneQuation Jan 22 '13 at 09:13
  • ummm what about `:/usr/lib/` right at the end of the `LIBRARY_PATH` line? – radman Jan 22 '13 at 09:39
  • Whoops! My bad, I must've looked at the wrong line after scrolling all the way to the right. ;) – IneQuation Jan 22 '13 at 10:34
  • Was your version of libGL.so a dangling symlink? – Marc Glisse Jan 22 '13 at 10:40
  • About your edit: was `/usr/lib/i386-linux-gnu/libGL.so` a dangling symlink? If so, I think you can put that as an answer to your own question. –  Jan 22 '13 at 10:41
  • @hvd, @Marc Glisse, turns out that yes `/usr/lib/i386-linux-gnu/libGL.so` was a symlink to a non-existing file, any ideas as to why this stopped the linker from continuing it's search? – radman Jan 22 '13 at 11:02
  • @radman It stops looking for `libGL.so` once it's found it. It shouldn't silently ignore the error on resolving the symlink: for all the linker knows, the symlink is correct but (for example) pointing to a file on a not currently mounted file system. Using `/usr/lib/libGL.so` in that case would be wrong. –  Jan 22 '13 at 11:49
  • @hvd, thanks for the explanation, it all makes sense now :) – radman Jan 22 '13 at 11:52

3 Answers3

1

After a bunch of digging it turns out that I was the victim of a dangling symlink (which is basically a symlink that doesn't link to something valid). So what happened is that the linker found a libGL.so at /usr/lib/i386-linux-gnu/libGL.so and decided that its search was over, however when it tried to get at the file there was nothing at the end of the symlink which caused the error message that I was seeing. Once I removed the dangling symlink the search didn't find a libGL.so until it got to the correct version at /usr/lib/libGL.so at which point everything worked as it should.

radman
  • 17,675
  • 11
  • 42
  • 58
0

Seems like your library path is not getting set for some reason. Does your configure have the option of setting --libexecdir=/usr/lib. I had similar problem where this option of --libexecdir was missing.

You can fix it by passing LDFLAGS in the makefile. How to use LDFLAGS in makefile is demistrated here. Your option of using -L/usr/lib is also perfect.

Community
  • 1
  • 1
spanky
  • 133
  • 1
  • 3
  • 11
  • 1
    Hi, I am aware that -L would be a workaround. I really want to know why /usr/lib is not being searched by default, I use a makefile generating tool and adding a superfluous -L to all makefiles is not the sort of solution I want to have. – radman Jan 22 '13 at 09:54
  • @radman Sorry for misunderstanding your question.After seeing your EDIT I am a bit confused myself. haha!!! – spanky Jan 22 '13 at 11:35
0

I just experienced a similar problem, when gcc required an explicit -L/usr/lib library search option; even though it should be already in the default library search path. Oddly, all libraries are available, ldconfig also located them properly.

Thanks to @radman finding, I recalled creating a symlink to .a static library which originally is installed in /usr/lib, but I added a symlink for it into /usr/lib/i386-linux-gnu while I was chasing some other configure/build issue.

Removing that symlink (valid, not dangling) cleared the library search problem, so gcc properly finds the library without the explicit -L/usr/lib

Rquest
  • 136
  • 3