Problems with LD

Hello,
I have a new PC on which I recently installed openSuse 12.2, it was supposed to be dual-boot but my openSuse install accidentally wiped out the Windows partition. Oh well, no big loss :wink:

Anyway, I am a developer and I have been having loads of trouble getting just about ANYTHING to compile. There seems to be a problem with ld (GNU linker) or something in the GNU toolchain. To illustrate I tried to compile a simple QT application and got the following:

g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/default -I. -I/usr/include/QtCore -I/usr/include -I. -o main.o main.cpp
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/default -I. -I/usr/include/QtCore -I/usr/include -I. -o propertyfile.o propertyfile.cpp
g++ -m64 -Wl,-O1 -o sqlite_props main.o propertyfile.o    -L/usr/lib64 -lQtCore -L/usr/lib64 -lpthread 
/usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../x86_64-suse-linux/bin/ld: warning: libz.so.1, needed by /usr/lib64/libQtCore.so, not found (try using -rpath or -rpath-link)
/usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../x86_64-suse-linux/bin/ld: warning: libdl.so.2, needed by /usr/lib64/libQtCore.so, not found (try using -rpath or -rpath-link)
/usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../x86_64-suse-linux/bin/ld: warning: librt.so.1, needed by /usr/lib64/libQtCore.so, not found (try using -rpath or -rpath-link)
/usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../x86_64-suse-linux/bin/ld: warning: libglib-2.0.so.0, needed by /usr/lib64/libQtCore.so, not found (try using -rpath or -rpath-link)

Now libz.so.1 and the other shared object files are absolutely in my search path for ld (they are in /lib64 which /etc/ld.so.conf says is
in the path, also I tried adding -L/lib64 directly to my compile options in the Makefile, nothing works.

Also if I do ldd on libQtCore.so I get:

ldd libQtCore.so.4.8.1
linux-vdso.so.1 (0x00007fff0b400000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f045ece8000)
libz.so.1 => /lib64/libz.so.1 (0x00007f045ead0000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f045e8c8000)
librt.so.1 => /lib64/librt.so.1 (0x00007f045e6c0000)
libglib-2.0.so.0 => /usr/lib64/libglib-2.0.so.0 (0x00007f045e3c8000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f045e0c0000)
libm.so.6 => /lib64/libm.so.6 (0x00007f045ddc8000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f045dbb0000)
libc.so.6 => /lib64/libc.so.6 (0x00007f045d808000)
/lib64/ld-linux-x86-64.so.2 (0x00007f045ef08000)
libpcre.so.1 => /usr/lib64/libpcre.so.1 (0x00007f045d5a8000)

The other problem I have on this system is that in some cases the shared library is found, but it complains about missing symbols, but the nm command shows that the supposedly symbols are there. Perhaps these problems are related …

Thanks to anyone who can provide some guidance on this perplexing question.

Cheers,
Craig

Hi
Have you added PKGCONFIG += <your_lib> and LIBS += -l<your_lib> in your
project file?

Have you checked through the resulting Makefile to see what it’s
creating?


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 12.2 (x86_64) Kernel 3.4.6-2.10-desktop
up 4:29, 3 users, load average: 0.06, 0.12, 0.26
CPU Intel i5 CPU M520@2.40GHz | Intel Arrandale GPU

Malcolm.
Thanks, Sorry for taking so long to reply.

My Makefile has the following relevant lines:

CC            = gcc
CXX           = g++
DEFINES       = -DQT_WEBKIT -DQT_NO_DEBUG -DQT_CORE_LIB -DQT_SHARED
CFLAGS        = -m64 -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)
CXXFLAGS      = -m64 -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)
INCPATH       = -I/usr/share/qt4/mkspecs/default -I. -I/usr/include/QtCore -I/usr/include -I.
LINK          = g++
LFLAGS        = -m64 -Wl,-O1
LIBS          = $(SUBLIBS)  -L/usr/lib64 -L/lib64 -lQtCore -L/usr/lib64 -lpthread

lib64 is there as you can see, this is the directory containing the .so files
that ld is complaining about.

And just to be thorough.

craig@linux-9fep:~/home/craig ls /lib64/libz*
/lib64/libz.so.1  /lib64/libz.so.1.2.7

I have not set PKGCONFIG. I am not familiar with this option, but reading a bit
about it it sounds like it is meant for linking to non-Qt libraries, whereas I am
only linking to the Qt libraries. Please let me know if I misunderstood.

Hi
What you need is something like;


$(SUBLIBS)  -L/usr/lib64 -lz -ldl -lrt -lglib-2.0 -L/usr/lib64 -lQtCore -lpthread

What happens if you hard code them in your project file?


LIBS += -lz -ldl -lrt -lglib-2.0

Note, only a packager/hacker here and not on qt stuff :wink:


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 12.2 (x86_64) Kernel 3.4.6-2.10-desktop
up 19:24, 4 users, load average: 0.01, 0.11, 0.18
CPU Intel i5 CPU M520@2.40GHz | Intel Arrandale GPU

That seems to have done the trick. In the end my .pro file looked like:

QT       += core
QT	 += sql

QT       -= gui

TARGET = sqlite_props
CONFIG   += console
CONFIG   -= app_bundle
LIBS += -lz -ldl -lrt -lglib-2.0 -lpcre
TEMPLATE = app


SOURCES += main.cpp \
    propertyfile.cpp

HEADERS += \
    propertyfile.h

In the end the parts I had to add where “LIBS += -lz -ldl -lrt -lglib-2.0 -lpcre”, and the “QT += sql”. It is odd that I need to specifically link to libraries needed by QtCore. Any idea why?

Thanks again for your help.

Craig

Hi
I imagine if you use PKGCONFIG it should afaik add them in so don’t
have to add manually.

Try adding to your project file (not sure of the pkgconfig names);


PKGCONFIG += zlib
PKGCONFIG += glib2

This should automatically add the flags based on the pc file
in /usr/lib{64}/pkgconfig/name.pc for example for glib-2.0;


prefix=/usr
exec_prefix=/usr
libdir=/usr/lib64
includedir=/usr/include

glib_genmarshal=glib-genmarshal
gobject_query=gobject-query
glib_mkenums=glib-mkenums

Name: GLib
Description: C Utility Library
Version: 2.32.3
Requires.private: libpcre
Libs: -L${libdir} -lglib-2.0
Libs.private: -pthread -lrt  -lpcre
Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib-2.0/include


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 12.2 (x86_64) Kernel 3.4.6-2.10-desktop
up 22:38, 3 users, load average: 0.03, 0.06, 0.05
CPU Intel i5 CPU M520@2.40GHz | Intel Arrandale GPU