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. [SOLVED] I can`t link my static library to my qt project
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] I can`t link my static library to my qt project

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 3.7k 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.
  • H Offline
    H Offline
    heatblazer
    wrote on 5 Jan 2015, 21:20 last edited by
    #1

    Hello, I have a custom utilities written in C, then outputed to static library. I`ve made include folder with the headers and lib folder with the so called "libutilz.a". In Qt creator pro file:
    @
    LIBS += -L/PATH_TO_LIB/lib/ -lutilz
    @

    Then when I compile it gives me
    @
    :-1: error: collect2: error: ld returned 1 exit status
    /home/ilian/QT5/DELETEME/main.cpp:-1: error: undefined reference to _getUtils()' @ [EDIT] It gives me undefined ref to my function which is in the .h file [EDIT] Ive solved it. I read about name mangling and understood that, actually, I had to wrap in extern "C" the include of my header like that:
    @
    extern "C" {
    #include "utils.h"
    }
    @
    That fixed the problem.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ambershark
      wrote on 5 Jan 2015, 23:45 last edited by
      #2

      What operating system?

      And how is libutilz.a built?

      It sounds like it is an invalid library. That is the behavior you see when Qt/gcc can't find any symbols in the library you are linking.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ambershark
        wrote on 5 Jan 2015, 23:47 last edited by
        #3

        If you are in Linux, what does the following command show:

        $ ar t libutilz.a

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        1 Reply Last reply
        0
        • H Offline
          H Offline
          heatblazer
          wrote on 5 Jan 2015, 23:55 last edited by
          #4

          libutilz was build with ar rcs libutilz.a myutil.o
          ar t libutilz.a reported me myutil.o

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ambershark
            wrote on 6 Jan 2015, 00:01 last edited by
            #5

            You can try linking directly to the lib:

            @
            LIBS += /my/path/libutilz.a
            @

            It is not able to use the library in your build. I don't know why but that is what is going on. It looks like the library has the myutil.o that you need, but for some reason it isn't working with your project.

            My guess (at least what I usually see on these forums and from developers) is that it is a lib that is built with incompatible settings to what is being used by the app.

            Most cases it is people trying to include a DLL built using MSVC in a project using mingw, or vice-versa.

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            0
            • A Offline
              A Offline
              ambershark
              wrote on 6 Jan 2015, 00:02 last edited by
              #6

              Also, you can try taking Qt out of it. Write a small app that use the myutil.o functions in a main.cpp.

              Then just build raw with gcc:

              @
              $ gcc -o test myapp.cpp -L/my/path/lib -lutilz
              @

              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

              1 Reply Last reply
              0
              • H Offline
                H Offline
                heatblazer
                wrote on 6 Jan 2015, 00:08 last edited by
                #7

                Will try it right on
                [quote author="ambershark" date="1420502577"]Also, you can try taking Qt out of it. Write a small app that use the myutil.o functions in a main.cpp.

                Then just build raw with gcc:

                @
                $ gcc -o test myapp.cpp -L/my/path/lib -lutilz
                @
                [/quote]

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  heatblazer
                  wrote on 6 Jan 2015, 00:14 last edited by
                  #8

                  I`ve tried it:
                  @
                  Test strip on Some foo bar stuff
                  result: [Somefoobarstuff]
                  @
                  Supposedly working the way you suggested.

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    heatblazer
                    wrote on 6 Jan 2015, 00:16 last edited by
                    #9

                    Oppps. Correction. I`ve tested in on main.c. Now in main.cpp it gives me the same error.

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      heatblazer
                      wrote on 6 Jan 2015, 00:56 last edited by
                      #10

                      Ive fixed it. Pfff. Its name mangling problem I should take note of from now on. Here is the fix:
                      in some of the main.cpp files when inlcuding "utils.h" do it like
                      @
                      extern "C" {
                      #include "utils.h"
                      }
                      @
                      I`ll add as sloved and fix.

                      1 Reply Last reply
                      0

                      1/10

                      5 Jan 2015, 21:20

                      • Login

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