PDA

View Full Version : Linking static libraries not compiled by qt?



blah900
20th July 2013, 17:00
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?

ChrisW67
20th July 2013, 22:38
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.

blah900
21st July 2013, 05:17
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.

ChrisW67
21st July 2013, 21:01
Using a 32- bit compiler with the 64- bit library?

blah900
21st July 2013, 22:06
My pro file looks like this


#-------------------------------------------------
#
# Project created by QtCreator 2013-07-20T21:20:18
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = EnetTest
TEMPLATE = app


SOURCES += main.cpp\
MainWindow.cpp

HEADERS += MainWindow.h \
enet/win32.h \
enet/utility.h \
enet/unix.h \
enet/types.h \
enet/time.h \
enet/protocol.h \
enet/list.h \
enet/enet.h \
enet/callbacks.h

FORMS += MainWindow.ui

LIBS += -LC:/testDirectory/enetTest -lenet64

And my main file looks like this

#include "MainWindow.h"
#include <QApplication>
#include "enet/enet.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
enet_initialize();
return a.exec();
}


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,