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
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.1k Views 1 Watching
  • 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 15 Jan 2024, 13:53 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

    J 1 Reply Last reply 15 Jan 2024, 14:17
    0
    • J JacobNovitsky
      15 Jan 2024, 13:53

      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

      J Online
      J Online
      jsulm
      Lifetime Qt Champion
      wrote on 15 Jan 2024, 14:17 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 15 Jan 2024, 14:28
      0
      • J jsulm
        15 Jan 2024, 14:17

        @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 15 Jan 2024, 14:28 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

        S 1 Reply Last reply 15 Jan 2024, 22:49
        0
        • J JacobNovitsky
          15 Jan 2024, 14:28

          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

          S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 15 Jan 2024, 22:49 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 16 Jan 2024, 09:16
          1
          • S SGaist
            15 Jan 2024, 22:49

            @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 16 Jan 2024, 09:16 last edited by
            #5

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

            S 1 Reply Last reply 16 Jan 2024, 09:21
            0
            • J JacobNovitsky
              16 Jan 2024, 09:16

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

              S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 16 Jan 2024, 09:21 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 16 Jan 2024, 09:25
              0
              • S SGaist
                16 Jan 2024, 09:21

                @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 16 Jan 2024, 09:25 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
                
                S 1 Reply Last reply 16 Jan 2024, 20:43
                0
                • J JacobNovitsky
                  16 Jan 2024, 09:25

                  @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
                  
                  S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 16 Jan 2024, 20:43 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

                  1/8

                  15 Jan 2024, 13:53

                  • Login

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