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. Unreferenced Libraries?
Qt 6.11 is out! See what's new in the release blog

Unreferenced Libraries?

Scheduled Pinned Locked Moved General and Desktop
16 Posts 4 Posters 6.5k 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 Offline
    J Offline
    JediSpam
    wrote on last edited by
    #1

    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
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      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
      0
      • J Offline
        J Offline
        JediSpam
        wrote on last edited by
        #3

        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
        0
        • L Offline
          L Offline
          loladiro
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            [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
            0
            • J Offline
              J Offline
              JediSpam
              wrote on last edited by
              #6

              [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
              0
              • L Offline
                L Offline
                lgeyer
                wrote on last edited by
                #7

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

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  loladiro
                  wrote on last edited by
                  #8

                  [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
                  0
                  • P Offline
                    P Offline
                    printingesco
                    wrote on last edited by
                    #9

                    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
                    0
                    • J Offline
                      J Offline
                      JediSpam
                      wrote on last edited by
                      #10

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

                      yes

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        JediSpam
                        wrote on last edited by
                        #11

                        [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
                        0
                        • L Offline
                          L Offline
                          loladiro
                          wrote on last edited by
                          #12

                          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
                          0
                          • J Offline
                            J Offline
                            JediSpam
                            wrote on last edited by
                            #13

                            [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
                            0
                            • L Offline
                              L Offline
                              loladiro
                              wrote on last edited by
                              #14

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

                              1 Reply Last reply
                              0
                              • L Offline
                                L Offline
                                lgeyer
                                wrote on last edited by
                                #15

                                [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
                                0
                                • J Offline
                                  J Offline
                                  JediSpam
                                  wrote on last edited by
                                  #16

                                  Thanks for the help guys!

                                  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