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. How to build .so files from existing C++ app using Qt Creator

How to build .so files from existing C++ app using Qt Creator

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 902 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.
  • J Offline
    J Offline
    JacobNovitsky
    wrote on last edited by
    #1

    I know how to create Shared Library using New Project / .. notation
    but how to make the same using existing project, it must be some flags/commands in Projects/Build/Run settings
    Please share the instructions
    tw.png

    jsulmJ 1 Reply Last reply
    0
    • J JacobNovitsky

      I know how to create Shared Library using New Project / .. notation
      but how to make the same using existing project, it must be some flags/commands in Projects/Build/Run settings
      Please share the instructions
      tw.png

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

      @JacobNovitsky Do you mean you want to change a project which builds to an executable so that a shared library is created instead?
      You need to change pro or CMakeLists.txt file of that project. You can simply compare it with a project which generates a shared library.

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

      J 1 Reply Last reply
      0
      • jsulmJ jsulm

        @JacobNovitsky Do you mean you want to change a project which builds to an executable so that a shared library is created instead?
        You need to change pro or CMakeLists.txt file of that project. You can simply compare it with a project which generates a shared library.

        J Offline
        J Offline
        JacobNovitsky
        wrote on last edited by JacobNovitsky
        #3

        In my shared library pro file there are following lines:

        CONFIG -= qt
        
        TEMPLATE = lib
        DEFINES += SHARED_LIBRARY
        
        CONFIG += c++17
        
        # You can make your code fail to compile if it uses deprecated APIs.
        # In order to do so, uncomment the following line.
        #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
        
        SOURCES += \
            Shared.cpp
        
        HEADERS += \
            shared_global.h \
            Shared.h
        
        # Default rules for deployment.
        unix {
            target.path = /usr/lib
        }
        !isEmpty(target.path): INSTALLS += target
        

        What should I do in .pro file of project I want to build to .so files?
        I can suppose that I need to create global shared_global.h analog for each class (header) I have?

        if so, should I make it manually or you have tool to make it automatically

        SGaistS 1 Reply Last reply
        0
        • J JacobNovitsky

          In my shared library pro file there are following lines:

          CONFIG -= qt
          
          TEMPLATE = lib
          DEFINES += SHARED_LIBRARY
          
          CONFIG += c++17
          
          # You can make your code fail to compile if it uses deprecated APIs.
          # In order to do so, uncomment the following line.
          #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
          
          SOURCES += \
              Shared.cpp
          
          HEADERS += \
              shared_global.h \
              Shared.h
          
          # Default rules for deployment.
          unix {
              target.path = /usr/lib
          }
          !isEmpty(target.path): INSTALLS += target
          

          What should I do in .pro file of project I want to build to .so files?
          I can suppose that I need to create global shared_global.h analog for each class (header) I have?

          if so, should I make it manually or you have tool to make it automatically

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @JacobNovitsky you are already using the lib template so it should build a library. You don't need one xxxx_globals.h per classe. It's a header that exists once per module.

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

          J 1 Reply Last reply
          1
          • SGaistS SGaist

            @JacobNovitsky you are already using the lib template so it should build a library. You don't need one xxxx_globals.h per classe. It's a header that exists once per module.

            J Offline
            J Offline
            JacobNovitsky
            wrote on last edited by
            #5

            @SGaist yes, understood
            but what should I do to make shared lib from existing project?

            SGaistS 1 Reply Last reply
            0
            • J JacobNovitsky

              @SGaist yes, understood
              but what should I do to make shared lib from existing project?

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @JacobNovitsky the project you are showing here already creates a library. That is the result you will get when compiling it.

              So what exactly is your issue ?

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

              J 1 Reply Last reply
              0
              • SGaistS SGaist

                @JacobNovitsky the project you are showing here already creates a library. That is the result you will get when compiling it.

                So what exactly is your issue ?

                J Offline
                J Offline
                JacobNovitsky
                wrote on last edited by JacobNovitsky
                #7

                @SGaist
                I'm trying to make .so file using this pro file for new C++ project

                TEMPLATE = lib
                CONFIG += c++17
                CONFIG -= app_bundle
                CONFIG -= qt

                SOURCES +=
                TestClass.cpp

                HEADERS +=
                TestClass.h

                Set the target type to shared

                CONFIG += shared

                Set the output directory for the shared library

                DESTDIR = /home/j/
                TARGET = $$DESTDIR/libTestLib.so

                it builds, but there is no .so file

                upd: this pro file version made these dirs and its contains
                j@j-BOHB-WAX9:~/testNewLib-Debug/shared-LIB/shared-LIB$ ls
                liblibTestLib.so.so liblibTestLib.so.so.1.0
                liblibTestLib.so.so.1 liblibTestLib.so.so.1.0.0

                TEMPLATE = lib
                CONFIG += c++17
                CONFIG -= app_bundle
                CONFIG -= qt
                
                SOURCES += \
                    TestClass.cpp
                
                HEADERS += \
                    TestClass.h
                
                # Set the target type to shared
                CONFIG += shared
                
                # Set the output directory for the shared library
                DESTDIR = shared-LIB
                TARGET = $$DESTDIR/libTestLib.so
                
                SGaistS 1 Reply Last reply
                0
                • J JacobNovitsky

                  @SGaist
                  I'm trying to make .so file using this pro file for new C++ project

                  TEMPLATE = lib
                  CONFIG += c++17
                  CONFIG -= app_bundle
                  CONFIG -= qt

                  SOURCES +=
                  TestClass.cpp

                  HEADERS +=
                  TestClass.h

                  Set the target type to shared

                  CONFIG += shared

                  Set the output directory for the shared library

                  DESTDIR = /home/j/
                  TARGET = $$DESTDIR/libTestLib.so

                  it builds, but there is no .so file

                  upd: this pro file version made these dirs and its contains
                  j@j-BOHB-WAX9:~/testNewLib-Debug/shared-LIB/shared-LIB$ ls
                  liblibTestLib.so.so liblibTestLib.so.so.1.0
                  liblibTestLib.so.so.1 liblibTestLib.so.so.1.0.0

                  TEMPLATE = lib
                  CONFIG += c++17
                  CONFIG -= app_bundle
                  CONFIG -= qt
                  
                  SOURCES += \
                      TestClass.cpp
                  
                  HEADERS += \
                      TestClass.h
                  
                  # Set the target type to shared
                  CONFIG += shared
                  
                  # Set the output directory for the shared library
                  DESTDIR = shared-LIB
                  TARGET = $$DESTDIR/libTestLib.so
                  
                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @JacobNovitsky TARGET should just contain the name of the library. Nothing else. No prefix, no suffix.

                  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
                  1

                  • Login

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