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 link .so files's header to other project

How to link .so files's header to other project

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 3 Posters 2.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 JacobNovitsky

    @jsulm

    main_project.cpp

    pro:

    TEMPLATE = app
    CONFIG += console c++17
    CONFIG -= app_bundle
    CONFIG -= qt
    
    LIBS += -L/home/j/shared-Debug/ -lshared
    INCLUDEPATH += /home/j/shared
    
    
    
    SOURCES += \
            main.cpp
    

    main.cpp:

    #include <iostream>
    #include <Shared.h>
    
    
    
    using namespace std;
    
    int main()
    {
        cout << "Hello World!" << endl;
        Shared s;
        s.test();
        return 0;
    }
    

    all correct now?
    it builds, but still I dont understand how it works

    So every time I have change in header, I need rebuild it to new so ?

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

    @JacobNovitsky said in How to link .so files's header to other project:

    So every time I have change in header, I need rebuild it to new so ?

    Your library mainly consists of the Shared.cpp. If you change the library header you may need to rebuild the library (depends on the changes in the header file) and also your main project.

    It is not that complex: you build the library to a so file. In the project where you want to use it you link the so (this is what LIBS is used for). But in order to use the functionality of the library in your main project (like using data types, calling functions, ...) you also need to include the header file from the library which defines the interface. This is done by adding INCLUDEPATH to tell the preprocessor where to look for header files and including the header file in your main project.

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

    1 Reply Last reply
    1
    • J JacobNovitsky

      @jsulm

      main_project.cpp

      pro:

      TEMPLATE = app
      CONFIG += console c++17
      CONFIG -= app_bundle
      CONFIG -= qt
      
      LIBS += -L/home/j/shared-Debug/ -lshared
      INCLUDEPATH += /home/j/shared
      
      
      
      SOURCES += \
              main.cpp
      

      main.cpp:

      #include <iostream>
      #include <Shared.h>
      
      
      
      using namespace std;
      
      int main()
      {
          cout << "Hello World!" << endl;
          Shared s;
          s.test();
          return 0;
      }
      

      all correct now?
      it builds, but still I dont understand how it works

      So every time I have change in header, I need rebuild it to new so ?

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

      @JacobNovitsky
      I just amended function in shared program, saved cpp but did not built and main program sees previous version

      jsulmJ 1 Reply Last reply
      0
      • J JacobNovitsky

        @JacobNovitsky
        I just amended function in shared program, saved cpp but did not built and main program sees previous version

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

        @JacobNovitsky said in How to link .so files's header to other project:

        I just amended function in shared program, saved cpp but did not built and main program sees previous version

        Not sure what this mean. If you mean you changed something in the shared library without rebuilding it and your main application still sees the old version then it is just logical, right? You need to rebuild the lib if you change it.

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

        J 1 Reply Last reply
        1
        • jsulmJ jsulm

          @JacobNovitsky said in How to link .so files's header to other project:

          I just amended function in shared program, saved cpp but did not built and main program sees previous version

          Not sure what this mean. If you mean you changed something in the shared library without rebuilding it and your main application still sees the old version then it is just logical, right? You need to rebuild the lib if you change it.

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

          @jsulm what is faster?
          pre-compiled headers or same headers built to objects?
          I used per-compiled headers and it seem to slightly speed up compilation, but I'm not sure

          jsulmJ 1 Reply Last reply
          0
          • J JacobNovitsky

            @jsulm what is faster?
            pre-compiled headers or same headers built to objects?
            I used per-compiled headers and it seem to slightly speed up compilation, but I'm not sure

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

            @JacobNovitsky I never used pre compiled headers and as far as I know only Microsoft compiler supports them (but I could be wrong on that).

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

            J SGaistS 2 Replies Last reply
            0
            • jsulmJ jsulm

              @JacobNovitsky I never used pre compiled headers and as far as I know only Microsoft compiler supports them (but I could be wrong on that).

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

              @jsulm oh! thanks :)
              any guideline how to speed compilation/execution/building time, on Ubuntu, Qt Creator 6.4.2, Qt6, gcc?
              I'd like to build all neat and fully debug function to so files, it seems reasonable, but I believe I can miss something powerful

              Pls advise :J

              jsulmJ 1 Reply Last reply
              0
              • jsulmJ jsulm

                @JacobNovitsky I never used pre compiled headers and as far as I know only Microsoft compiler supports them (but I could be wrong on that).

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

                @jsulm said in How to link .so files's header to other project:

                @JacobNovitsky I never used pre compiled headers and as far as I know only Microsoft compiler supports them (but I could be wrong on that).

                Pre-compiled headers are available through gcc and clang as well.

                @JacobNovitsky before diving into that kind of consideration, you should first analyze what you are currently using for your application. You example library does not really warrant the use of pre-compiled headers seeing the side and number of includes it has. Take a look at the Wikipedia entry.

                As for debugging, you might want to check the "release with debug info" topic. Note that you should first start with a working implementation and then pursue optimization.

                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
                2
                • J JacobNovitsky

                  @jsulm oh! thanks :)
                  any guideline how to speed compilation/execution/building time, on Ubuntu, Qt Creator 6.4.2, Qt6, gcc?
                  I'd like to build all neat and fully debug function to so files, it seems reasonable, but I believe I can miss something powerful

                  Pls advise :J

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

                  @JacobNovitsky Do you use more than one build process? With make you can do that like this: make -j NUMBER_OF_PARALLEL_BUILD_JOBS
                  I think QtCreator does this by default already.

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

                  J 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @JacobNovitsky Do you use more than one build process? With make you can do that like this: make -j NUMBER_OF_PARALLEL_BUILD_JOBS
                    I think QtCreator does this by default already.

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

                    @jsulm yes, it uses "/usr/bin/make" -j8
                    but still it calls 30-60 seconds per build, which is way too much

                    jsulmJ 1 Reply Last reply
                    0
                    • J JacobNovitsky

                      @jsulm yes, it uses "/usr/bin/make" -j8
                      but still it calls 30-60 seconds per build, which is way too much

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

                      @JacobNovitsky said in How to link .so files's header to other project:

                      but still it calls 30-60 seconds per build

                      Are we talking about complete rebuild of the project or incremental builds after changing some parts of the code? How big is the project (how many lines of code)?

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

                      1 Reply Last reply
                      2

                      • Login

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