Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. static compilation with sonames without specifying it
Forum Updated to NodeBB v4.3 + New Features

static compilation with sonames without specifying it

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
static linkingdynamic linklinux
4 Posts 2 Posters 631 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.
  • G Offline
    G Offline
    genner
    wrote on last edited by genner
    #1

    Hi all,

    I am experiencing a strange behavior. I am compiling a library without passing any static / staticlib option, but apparently it gets statically compiled somehow.

    It correctly generates a .so file (I'm on Linux), but when I check it with ldd I see: "statically linked
    " as output.

    I printed what is written in CONFIG and everything seems correct:

    lex yacc debug exceptions depend_includepath testcase_targets import_plugins import_qpa_plugin file_copies qmake_use qt warn_on release link_prl incremental shared plugin_manifest linux unix posix gcc qtc_run debug qml_debug qtc_run c++11 console
    

    If I add other similar libraries and try to link them, I cannot be able to create dynamic libraries in any way.

    This is the code:

    QT -= gui
    
    TEMPLATE = lib
    DEFINES += MY_FIRST_LIBRARY
    
    CONFIG += c++11
    
    DESTDIR = ../lib
    MOC_DIR = ../build
    OBJECTS_DIR = ../build
    TARGET = my_first
    
    
    DEFINES += QT_DEPRECATED_WARNINGS
    
    SOURCES += \
        first_class.cpp
    
    HEADERS += \
        first_class.h \
        my_first_global.h \
    
    # Default rules for deployment.
    unix {
        target.path = /usr/lib
    }
    !isEmpty(target.path): INSTALLS += target
    

    What's going on in your opinion? any hint on how to debug it ?

    Cheers

    [EDIT 1]
    Some more info: the generated Makefile has following flags:

    CFLAGS        = -pipe -O2 -Wall -Wextra -D_REENTRANT -fPIC $(DEFINES)
    CXXFLAGS      = -pipe -O2 -std=gnu++1z -Wall -Wextra -D_REENTRANT -fPIC $(DEFINES)
    LINK          = g++
    LFLAGS        = -Wl,-O1 -Wl,-rpath,/home/genner/Qt/6.3.0/gcc_64/lib -Wl,-rpath-link,/home/genner/Qt/6.3.0/gcc_64/lib -shared -Wl,-soname,libmy_first.so.1
    LIBS          = $(SUBLIBS) /home/genner/Qt/6.3.0/gcc_64/lib/libQt6Gui.so /home/genner/Qt/6.3.0/gcc_64/lib/libQt6Core.so -lpthread -lGL   
    

    EDIT 2:
    The file command tells me this:

    libmy_first.so.1.0.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=20250f39bd468b237bfcaac47960d8381f1e5ebe, with debug_info, not stripped
    

    Again, ldd tells me instead:

    statically linked
    
    jsulmJ 1 Reply Last reply
    0
    • G genner

      Hi all,

      I am experiencing a strange behavior. I am compiling a library without passing any static / staticlib option, but apparently it gets statically compiled somehow.

      It correctly generates a .so file (I'm on Linux), but when I check it with ldd I see: "statically linked
      " as output.

      I printed what is written in CONFIG and everything seems correct:

      lex yacc debug exceptions depend_includepath testcase_targets import_plugins import_qpa_plugin file_copies qmake_use qt warn_on release link_prl incremental shared plugin_manifest linux unix posix gcc qtc_run debug qml_debug qtc_run c++11 console
      

      If I add other similar libraries and try to link them, I cannot be able to create dynamic libraries in any way.

      This is the code:

      QT -= gui
      
      TEMPLATE = lib
      DEFINES += MY_FIRST_LIBRARY
      
      CONFIG += c++11
      
      DESTDIR = ../lib
      MOC_DIR = ../build
      OBJECTS_DIR = ../build
      TARGET = my_first
      
      
      DEFINES += QT_DEPRECATED_WARNINGS
      
      SOURCES += \
          first_class.cpp
      
      HEADERS += \
          first_class.h \
          my_first_global.h \
      
      # Default rules for deployment.
      unix {
          target.path = /usr/lib
      }
      !isEmpty(target.path): INSTALLS += target
      

      What's going on in your opinion? any hint on how to debug it ?

      Cheers

      [EDIT 1]
      Some more info: the generated Makefile has following flags:

      CFLAGS        = -pipe -O2 -Wall -Wextra -D_REENTRANT -fPIC $(DEFINES)
      CXXFLAGS      = -pipe -O2 -std=gnu++1z -Wall -Wextra -D_REENTRANT -fPIC $(DEFINES)
      LINK          = g++
      LFLAGS        = -Wl,-O1 -Wl,-rpath,/home/genner/Qt/6.3.0/gcc_64/lib -Wl,-rpath-link,/home/genner/Qt/6.3.0/gcc_64/lib -shared -Wl,-soname,libmy_first.so.1
      LIBS          = $(SUBLIBS) /home/genner/Qt/6.3.0/gcc_64/lib/libQt6Gui.so /home/genner/Qt/6.3.0/gcc_64/lib/libQt6Core.so -lpthread -lGL   
      

      EDIT 2:
      The file command tells me this:

      libmy_first.so.1.0.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=20250f39bd468b237bfcaac47960d8381f1e5ebe, with debug_info, not stripped
      

      Again, ldd tells me instead:

      statically linked
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @genner What is the target device/OS you're building for? What Qt do you use (is it statically linked?)?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      G 1 Reply Last reply
      0
      • jsulmJ jsulm

        @genner What is the target device/OS you're building for? What Qt do you use (is it statically linked?)?

        G Offline
        G Offline
        genner
        wrote on last edited by
        #3

        @jsulm target is Linux as well, and I have just installed the last Qt 6.3.0 version without doing anything particular.

        G 1 Reply Last reply
        0
        • G genner

          @jsulm target is Linux as well, and I have just installed the last Qt 6.3.0 version without doing anything particular.

          G Offline
          G Offline
          genner
          wrote on last edited by
          #4

          Ok, apparently the library did not contain much code. Adding more code it now correctly shows that it is a dynamic library also with ldd.

          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