Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SOLVED: Linker problem using shared library with incompatible ELF headers when using QVariant
QtWS25 Last Chance

SOLVED: Linker problem using shared library with incompatible ELF headers when using QVariant

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kuschky
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Sounds strange, how did you install Qt ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kuschky
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kuschky
          wrote on last edited by
          #4

          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-build

          LIBS += -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-build

          LIBS += -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 recognized

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

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kuschky
              wrote on last edited by
              #6

              Yes I know, that's why I'm setting the quotes ;-) But Qt is not setting the single LIBS blocks simply together like they come in the .pro file. One "-L" is lost when the mistaken blanks are in. So, there happens some parsing and formating before.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved