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. Link project with inner library
Forum Updated to NodeBB v4.3 + New Features

Link project with inner library

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 463 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.
  • M Offline
    M Offline
    masa4
    wrote on last edited by masa4
    #1

    I added a code folder to my project with some classes and a library folder. Library folder consist some header files that used in classes and a .so file. It is like that:
    codefolder:

    .
    ├── Class1.cpp
    ├── Class1.h
    ├── Class2.cpp
    ├── Class2.h
    └── mylib
        ├── include
        │   ├── header1.h
        │   ├── header2.h
        │   ├── header3.h
        │   ├── ...
        └── lib
            └── libmylib.so
    

    I added whole codefolder to my project, qt creator added all cpp and headers to my project, but .so file added like this in .pro:

    DISTFILES += \
        codefolder/mylib/lib/libmylib.so
    

    Now I got several error like undefined reference to XXX class, XXX is which lays in mylibs library. Now how i can link this library with my project. I tried several thing but didnt work. And why my .so added as distfile, what is it?

    EDIT:

    LIBS += <full_path_to_so> #works
    LIBS += <relative_path_to_so> #does not work
    

    When I tried with full path it worked in this way. Any way to make it work with relative path?

    jsulmJ 1 Reply Last reply
    0
    • M masa4

      I added a code folder to my project with some classes and a library folder. Library folder consist some header files that used in classes and a .so file. It is like that:
      codefolder:

      .
      ├── Class1.cpp
      ├── Class1.h
      ├── Class2.cpp
      ├── Class2.h
      └── mylib
          ├── include
          │   ├── header1.h
          │   ├── header2.h
          │   ├── header3.h
          │   ├── ...
          └── lib
              └── libmylib.so
      

      I added whole codefolder to my project, qt creator added all cpp and headers to my project, but .so file added like this in .pro:

      DISTFILES += \
          codefolder/mylib/lib/libmylib.so
      

      Now I got several error like undefined reference to XXX class, XXX is which lays in mylibs library. Now how i can link this library with my project. I tried several thing but didnt work. And why my .so added as distfile, what is it?

      EDIT:

      LIBS += <full_path_to_so> #works
      LIBS += <relative_path_to_so> #does not work
      

      When I tried with full path it worked in this way. Any way to make it work with relative path?

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

      @masa4 You should set-up subdirs project, see "Solution #2: with "depends" attribute" in https://stackoverflow.com/questions/52882348/how-do-i-add-a-subproject-on-which-my-main-project-is-dependent-in-qt

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

      M 2 Replies Last reply
      0
      • jsulmJ jsulm

        @masa4 You should set-up subdirs project, see "Solution #2: with "depends" attribute" in https://stackoverflow.com/questions/52882348/how-do-i-add-a-subproject-on-which-my-main-project-is-dependent-in-qt

        M Offline
        M Offline
        masa4
        wrote on last edited by
        #3

        @jsulm By the way the codefolder i added is not a qt project. just regular cpp and h files with additional .so file. Now i will look at it, thanks

        1 Reply Last reply
        0
        • jsulmJ jsulm

          @masa4 You should set-up subdirs project, see "Solution #2: with "depends" attribute" in https://stackoverflow.com/questions/52882348/how-do-i-add-a-subproject-on-which-my-main-project-is-dependent-in-qt

          M Offline
          M Offline
          masa4
          wrote on last edited by
          #4

          @jsulm Nope, it didnt work

          jsulmJ 1 Reply Last reply
          0
          • M masa4

            @jsulm Nope, it didnt work

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

            @masa4 said in Link project with inner library:

            it didnt work

            Not a good description of a problem...

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

            M 1 Reply Last reply
            0
            • jsulmJ jsulm

              @masa4 said in Link project with inner library:

              it didnt work

              Not a good description of a problem...

              M Offline
              M Offline
              masa4
              wrote on last edited by
              #6

              @jsulm Do you know a way to use LIBS with relative way? for link u shared with me, I am not sure maybe i did it wrong but the guy asking something different in that link. So I tried using LIBS again with full path and it worked. But I need relative path so program will be eligible for building at another computers/another paths too.

              jsulmJ 1 Reply Last reply
              0
              • M masa4

                @jsulm Do you know a way to use LIBS with relative way? for link u shared with me, I am not sure maybe i did it wrong but the guy asking something different in that link. So I tried using LIBS again with full path and it worked. But I need relative path so program will be eligible for building at another computers/another paths too.

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

                @masa4 said in Link project with inner library:

                LIBS with relative way?

                What is the problem? Simply use a relative path like

                LIBS += -Lsome_folder -llib_name
                

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

                M 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @masa4 said in Link project with inner library:

                  LIBS with relative way?

                  What is the problem? Simply use a relative path like

                  LIBS += -Lsome_folder -llib_name
                  
                  M Offline
                  M Offline
                  masa4
                  wrote on last edited by
                  #8

                  @jsulm

                  LIBS += -Lcodefolder/mylib/lib/ -llibmylib #cannot find -llibmylib - no such file or directory
                  LIBS += -Lcodefolder/mylib/lib/ -lmylib #cannot find -lmylib - no such file or directory
                  

                  Both version gives these errors.

                  jsulmJ 1 Reply Last reply
                  0
                  • M masa4

                    @jsulm

                    LIBS += -Lcodefolder/mylib/lib/ -llibmylib #cannot find -llibmylib - no such file or directory
                    LIBS += -Lcodefolder/mylib/lib/ -lmylib #cannot find -lmylib - no such file or directory
                    

                    Both version gives these errors.

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

                    @masa4 So, is there a lib called libmylib.so inside codefolder/mylib/lib?
                    Why would you put a binary of your lib into your source code tree AND also add the code of the lib to your project? This does not make sense and that's why I suggested to do it properly using subdirs project...

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

                    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