SOLVED: Linker problem using shared library with incompatible ELF headers when using QVariant
-
I'm working on a Qt 5.3.2 shared library running on Linux x86 32bit systems. First everything was o.k. but than there are problem coming up that the main application could not be linked to the shared library anymore. The compiler told me the following
@
/usr/bin/ld: cannot find ../mysharedlibrary: File format not recognized
@I chekced the generated main program and the shared library with the file command. The reason seems to be that the ELF header of my main program got identified as GNU/Linux and the header of my sharedlibrary as SYSV
@
libmysharedlibrary.so.1.0.0: ELF 32-bit LSB shared object, Intel 80386, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=35a2408f301eb8749722b391d2d0e35b4741ea53, not stripped
@@
mainprogram: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=f104a5a5345514064c75b4ecb02f3d13a6c7aa77, not stripped
@I checked (with file command) the standard libs of the Linux (Mint Qiana 32bit) and all are of type SYSV. Than I stripped down my main program by removing all implemented code and variables. At this point it was build as SYSV like wanted. Then I added function by function and found out that as soon I'm using a QVariant the application was linked iwth GNU/Linux Elf header which is unable to linked together with SYSV libraries.
Does anybody how to control which type of header is generated and how to configure the Qt project to working fine. Thanks for every suggestions.
-
Hi,
Sounds strange, how did you install Qt ?
-
I did download the self extracting linux 32 bit version which comes bundled with the QtCreator 3.2.1. I played a lttle bit more with it and know it switches to GNU/Linux when I add the follwoing line
@
QList<SimpleQObjectClass*>* objects = variant.value<QList<SimpleQObjectClass*>* >();
@when I outcoment the line it flips back to SYSV after compiling.
There is still a Qt 5.2.0 installation in parallel in different directories. Can this have an effect to the Qt 5.3.2 installation? The paths seen while compiling are pointing to the 5.3.2 installation.
I checked what ELF Type the binaries generated with the old 5.2.0 installation (created before 5.3.2 was installed) they have SYSV as ELF type
-
Problem solved. It was a mistake from my side in the .pro file :-(
wrong version
@
LIBS += -L $$PWD/../lib1-build/ -llib1
INCLUDEPATH += $$PWD/../lib1-build
DEPENDPATH += $$PWD/../lib1-buildLIBS += -L $$PWD/../lib2-build/ -llib2 INCLUDEPATH += $$PWD/../lib2-build DEPENDPATH += $$PWD/../lib2-build
@
corrected version
@
LIBS += -L$$PWD/../lib1-build/ -llib1
INCLUDEPATH += $$PWD/../lib1-build
DEPENDPATH += $$PWD/../lib1-buildLIBS += -L$$PWD/../lib2-build/ -llib2 INCLUDEPATH += $$PWD/../lib2-build DEPENDPATH += $$PWD/../lib2-build
@
The mistake are the spaces after the -L option. That resulted in a linker command that looks like this
@
g++ -Wl,-rpath,/home/username/Qt5.3.2/5.3/gcc -Wl,-rpath,/home/username/Qt5.3.2/5.3/gcc/lib -Wl,-rpath-link,/home/username/Qt5.3.2/5.3/gcc/lib -o myprogram main.o -L ../mylib1-build -lmylib1 ../mylib2-build -lmylib2 -L/home/username/Qt5.3.2/5.3/gcc/lib -lQt5Declarative -lQt5XmlPatterns -lQt5Sql -lQt5Qml -lQt5Multimedia -lQt5Widgets -lQt5Network -lQt5Script -lQt5Gui -lQt5Core -lGL -lpthread
@
Then Qt "forgets" to set the second -L option and ../mylib2-build directory is interpreted as library which does does have the a library type. That results in the error message: File format not recognizedThe libraries still have different type SYSV and GNU/Linux but this is not a problem for the linker. Even if it doesn't matter I searched the web and don#t found an explanation whythe libraries get different types when they are build.
That's it.
-
Nice you found out !
It's not Qt that forgets something, the flags are passed to the linker that will fail to used them with this supplementary space
-