Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unreferenced Libraries?

    General and Desktop
    4
    16
    3980
    Loading More Posts
    • 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
      JediSpam last edited by

      Alright,

      I am having a lot of trouble correctly linking libraries to QT 4. I created a simple library called test_class and here is the code:

      test_class.cpp
      @
      #include "test_class.h"

      int test_me::whatever(void)
      {
      return 5;
      }
      @

      test_class.h
      @
      #ifndef TEST_CLASS_H
      #define TEST_CLASS_H

      class test_me
      {
      public:
      int whatever(void);
      };

      #endif
      @

      I then create that into a .lib and try to call it from my other program in this manner:
      @
      MainWindow.cpp

      test_me abc;
      abc.whatever();
      

      @

      I have the proper include in MainWindow.cpp and I have the library in my .pro file correct. Any ideas? I'm getting this as an error:

      Quoted
      
      mainwindow.cpp:26: error: undefined reference to `test_me::whatever()'
      :-1: error: collect2: ld returned 1 exit status
      
      1 Reply Last reply Reply Quote 0
      • L
        lgeyer last edited by

        Have you added the library to LIBS? Is it properly listed in the linker command when compiling / linking the project?
        @
        LIBS += -L<path to library> -l<library name>
        @

        1 Reply Last reply Reply Quote 0
        • J
          JediSpam last edited by

          Yes i have added the library to my .pro file
          @
          unix|win32: LIBS += -ltest_code -LC:\VS13_VIEWS\libs
          @

          just tried the syntax you posted and still no go

          1 Reply Last reply Reply Quote 0
          • L
            loladiro last edited by

            You are not exporting the class.
            If you are using Qt Creator, have a look at the library template.

            1 Reply Last reply Reply Quote 0
            • L
              lgeyer last edited by

              [quote author="JediSpam" date="1313071868"]I then create that into a .lib[/quote]

              Are we talking about a static library or a shared library?

              1 Reply Last reply Reply Quote 0
              • J
                JediSpam last edited by

                [quote author="Lukas Geyer" date="1313072764"][quote author="JediSpam" date="1313071868"]I then create that into a .lib[/quote]

                Are we talking about a static library or a shared library? If so you will have to export symbols as loladiro said.[/quote]

                this is a static library i have created in visual studio 2003. i'm trying to understand the library template stuff

                1 Reply Last reply Reply Quote 0
                • L
                  lgeyer last edited by

                  You might use the nm tool to see which symbols are exported from your library.

                  1 Reply Last reply Reply Quote 0
                  • L
                    loladiro last edited by

                    [quote]
                    this is a static library i have created in visual studio 2003.
                    [/quote]
                    Are you trying to mix MSVC and MinGW-compiled code? Not a good Idea!!

                    1 Reply Last reply Reply Quote 0
                    • P
                      printingesco last edited by

                      You talking about static library ?

                      [url=http://www.print-print.co.uk/Poster-Printing.asp]Poster Printing [/url]| [url=http://www.print-print.co.uk/Poster-Printing.asp]Cheap Leaflet P...

                      1 Reply Last reply Reply Quote 0
                      • J
                        JediSpam last edited by

                        [quote author="printingesco" date="1313075382"]You talking about static library ?[/quote]

                        yes

                        1 Reply Last reply Reply Quote 0
                        • J
                          JediSpam last edited by

                          [quote author="loladiro" date="1313072534"]You are not exporting the class.
                          If you are using Qt Creator, have a look at the library template.[/quote]

                          I read the qMake Project Files section "Declaring Other Libraries" and don't see what I haven't done correctly.

                          [quote author="Lukas Geyer" date="1313072949"]You might use the nm tool to see which symbols are exported from your library.[/quote]

                          Is this a QT tool I don't see it anywhere

                          1 Reply Last reply Reply Quote 0
                          • L
                            loladiro last edited by

                            Again, did you compile your library with mingw? It doesn't seem that way because mingw static library files have a .a extension. You cannot mix MSVC and MinGW.

                            1 Reply Last reply Reply Quote 0
                            • J
                              JediSpam last edited by

                              [quote author="loladiro" date="1313076573"]Again, did you compile your library with mingw? It doesn't seem that way because mingw static library files have a .a extension. You cannot mix MSVC and MinGW.[/quote]

                              ah i see. so i'd have to use the MinGW in visual studio to build a library.

                              1 Reply Last reply Reply Quote 0
                              • L
                                loladiro last edited by

                                You'd have to either build both the library and app with MinGW or both with MSVC.

                                1 Reply Last reply Reply Quote 0
                                • L
                                  lgeyer last edited by

                                  [quote author="JediSpam" date="1313076335"]
                                  [quote author="Lukas Geyer" date="1313072949"]You might use the nm tool to see which symbols are exported from your library.[/quote]
                                  Is this a QT tool I don't see it anywhere
                                  [/quote]

                                  nm comes with MinGW, which is part of the Qt SDK. Just open a Qt command promt and type nm <binary> to get a list of exported symbols.

                                  (Although it comes with MinGW it should work with any PE - read MSVC - binaries).

                                  1 Reply Last reply Reply Quote 0
                                  • J
                                    JediSpam last edited by

                                    Thanks for the help guys!

                                    1 Reply Last reply Reply Quote 0
                                    • First post
                                      Last post