/usr/lib appears not to be a default link location

假如想象 提交于 2019-12-24 09:01:08

问题


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

回答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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/14454375/usr-lib-appears-not-to-be-a-default-link-location

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!