Results 1 to 5 of 5

Thread: Linking static libraries not compiled by qt?

  1. #1
    Join Date
    Jul 2013
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Linking static libraries not compiled by qt?

    I have searched for a while and I keep seeing posts that you need to compile the libraries again in qt to get the proper library files. Is this true?

    I am asking because I wanted to use the enet library found http://enet.bespin.org.

    I tried including the enet64.lib and enet.lib in the pro file by copying the enet libraries into the directory and using LIBS += -lenet64 and LIBS += -lenet
    Then I included the necessary header files found in the directory.

    However it keeps saying that I have unresolved external symbol which should be defined in the library.

    Any ideas?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Linking static libraries not compiled by qt?

    Quote Originally Posted by blah900 View Post
    I have searched for a while and I keep seeing posts that you need to compile the libraries again in qt to get the proper library files. Is this true?
    No, you don't compile anything in Qt... Qt is not a compiler it is a library.

    All the components you link together with your C++ probject must be compatible. If they use C++ linkage then libraries must be built with a compatible (usually the same) compiler. If they use C linkage (i.e. declared extern "C"{}) then the library can be built with almost any compiler and linked with your project.
    I am asking because I wanted to use the enet library found http://enet.bespin.org.
    Your library falls in the latter group.
    I tried including the enet64.lib and enet.lib in the pro file by copying the enet libraries into the directory and using LIBS += -lenet64 and LIBS += -lenet
    You are either building a 32-bit or 64-bit executable, but not both at the same time.
    However it keeps saying that I have unresolved external symbol which should be defined in the library.
    Yes, the linker cannot find the library (the -L option in LIBS) or your code is broken in some entirely unrelated way. We can only guess.

  3. #3
    Join Date
    Jul 2013
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Linking static libraries not compiled by qt?

    Okay so far I did the following:

    I created a project directory called C:/testDirectory

    Inside that I created a project called enetTest, which is a qt gui application

    So the entire project files are inside C:/testDirectory/enetTest

    Inside that directory I copied enet64.lib

    So the library is inside C:/testDirectory/enetTest

    I also copied the directory with all the header files into the enet directory inside the project directory. So they ar ein C:/testDirectory/enetTest/enet

    Inside the pro file I added the line:
    LIBS += -LC:/testDirectory/enetTest -lenet64 (I also tried just -lenet64 since the relative path is just there)

    And inside the main.cpp I put #include <enet/enet.h> and also tried #include "enet/enet.h" as well as "enet.h" and <enet.h>

    And then I call the enet_initialize() which is inside the enet.h inside the library.

    However this results in
    LNK2019: unresolved external symbol enet_initialize referenced in function main.

    But when I ctrl+click inside the qt creator it takes me to that function so it seems that it has an idea of where to go in qt creator.

    I'm still unclear as to what I am doing wrong.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Linking static libraries not compiled by qt?

    Using a 32- bit compiler with the 64- bit library?

  5. #5
    Join Date
    Jul 2013
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Linking static libraries not compiled by qt?

    My pro file looks like this
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2013-07-20T21:20:18
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8.  
    9. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    10.  
    11. TARGET = EnetTest
    12. TEMPLATE = app
    13.  
    14.  
    15. SOURCES += main.cpp\
    16. MainWindow.cpp
    17.  
    18. HEADERS += MainWindow.h \
    19. enet/win32.h \
    20. enet/utility.h \
    21. enet/unix.h \
    22. enet/types.h \
    23. enet/time.h \
    24. enet/protocol.h \
    25. enet/list.h \
    26. enet/enet.h \
    27. enet/callbacks.h
    28.  
    29. FORMS += MainWindow.ui
    30.  
    31. LIBS += -LC:/testDirectory/enetTest -lenet64
    To copy to clipboard, switch view to plain text mode 

    And my main file looks like this
    Qt Code:
    1. #include "MainWindow.h"
    2. #include <QApplication>
    3. #include "enet/enet.h"
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9. enet_initialize();
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    Using MSVC2012 64bit compiler, when I call enet_initialize() , it now can call enet_initialize() but says that there are unresolved exernal symbol (name of function) referenced in function enet_initialize(and other functions inside the library) ...... enet64.lib(win32.o). These are all functions that are defined inside the library so they are defined.

    Am I supposed to include anything else with the lib? I did need to include the include headers right? The enet/*.h.

    Much appreciated,

Similar Threads

  1. Replies: 4
    Last Post: 5th November 2011, 02:38
  2. Replies: 3
    Last Post: 1st June 2011, 16:32
  3. static and dynamic libraries linking
    By buddax2 in forum Newbie
    Replies: 2
    Last Post: 27th December 2010, 16:55
  4. Replies: 2
    Last Post: 31st October 2009, 04:41
  5. Problem when linking with own static libraries
    By herveT in forum Qt Programming
    Replies: 4
    Last Post: 6th May 2009, 09:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.