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. Automatically include needed files in .pro file
Forum Updated to NodeBB v4.3 + New Features

Automatically include needed files in .pro file

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 329 Views 2 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.
  • ocgltdO Offline
    ocgltdO Offline
    ocgltd
    wrote on last edited by
    #1

    I have been experimenting with creating shared libraries under linux. All is working well but i've discovered something unusual.

    I can use/reference some other class in my .so file and it compiles without issue. However, when I try to use methods in the .so file the app crashes dues to symbol undefined or similar.

    It seems that I must add the .h and .cpp for every class I reference in my library into the .pro file for the lib; otherwise I get runtime errors (but no compilation errors) Is this normal?

    Next, is there a way for Qt Creator to automatically add all of the needed .h and .cpp files (references by files in the .so) into my .pro file? Or do I have to add them all by hand?

    jsulmJ 1 Reply Last reply
    0
    • ocgltdO ocgltd

      @jsulm I actually meant the other way around. The .so is accessing classes/methods in the app (that loads the .so)...so it seems I have to include those classes' .h and .cpp when compiling the .so

      I would like QT to automatically figure out which .h and .cpp files my shared library needs and add them to the library's .pro

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #5

      @ocgltd It is totally up to you how to build shared libs, like which classes are added to .so. Qt can not automatically detect what is included in the lib. But when Qt code uses any of classes which are supposed to be in the lib, they should be there. Otherwise, you will see errors like undefined symbols.

      1 Reply Last reply
      0
      • ocgltdO ocgltd

        I have been experimenting with creating shared libraries under linux. All is working well but i've discovered something unusual.

        I can use/reference some other class in my .so file and it compiles without issue. However, when I try to use methods in the .so file the app crashes dues to symbol undefined or similar.

        It seems that I must add the .h and .cpp for every class I reference in my library into the .pro file for the lib; otherwise I get runtime errors (but no compilation errors) Is this normal?

        Next, is there a way for Qt Creator to automatically add all of the needed .h and .cpp files (references by files in the .so) into my .pro file? Or do I have to add them all by hand?

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

        @ocgltd You need to export symbols you want to use outside of the library. See https://doc.qt.io/qt-6/sharedlibrary.html
        Then only header file from the lib is needed where the library is used.

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

        ocgltdO 1 Reply Last reply
        1
        • jsulmJ jsulm

          @ocgltd You need to export symbols you want to use outside of the library. See https://doc.qt.io/qt-6/sharedlibrary.html
          Then only header file from the lib is needed where the library is used.

          ocgltdO Offline
          ocgltdO Offline
          ocgltd
          wrote on last edited by
          #3

          @jsulm I actually meant the other way around. The .so is accessing classes/methods in the app (that loads the .so)...so it seems I have to include those classes' .h and .cpp when compiling the .so

          I would like QT to automatically figure out which .h and .cpp files my shared library needs and add them to the library's .pro

          Christian EhrlicherC JoeCFDJ 2 Replies Last reply
          0
          • ocgltdO ocgltd

            @jsulm I actually meant the other way around. The .so is accessing classes/methods in the app (that loads the .so)...so it seems I have to include those classes' .h and .cpp when compiling the .so

            I would like QT to automatically figure out which .h and .cpp files my shared library needs and add them to the library's .pro

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @ocgltd said in Automatically include needed files in .pro file:

            I would like QT to automatically figure out which .h and .cpp files my shared library needs and add them to the library's .pro

            why would you add e.g. iostream header to your pro file?

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            0
            • ocgltdO ocgltd

              @jsulm I actually meant the other way around. The .so is accessing classes/methods in the app (that loads the .so)...so it seems I have to include those classes' .h and .cpp when compiling the .so

              I would like QT to automatically figure out which .h and .cpp files my shared library needs and add them to the library's .pro

              JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote on last edited by
              #5

              @ocgltd It is totally up to you how to build shared libs, like which classes are added to .so. Qt can not automatically detect what is included in the lib. But when Qt code uses any of classes which are supposed to be in the lib, they should be there. Otherwise, you will see errors like undefined symbols.

              1 Reply Last reply
              0
              • ocgltdO ocgltd has marked this topic as solved on

              • Login

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