I'm newbie in C++ programming. I started from Qt 5.0.1. I need to use WebSockets from: https://code.google.com/p/tufao/ but I don't have MinGW installation so I googled that I can create Qt library project, include these source files and build static library. So I did it:
QT += network
QT -= gui
TARGET = tufao
TEMPLATE = lib
CONFIG += staticlib
INCLUDEPATH = src src/priv
SOURCES += \
src/websocket.cpp \
src/url.cpp \
src/simplesessionstore.cpp \
src/sessionstore.cpp \
src/querystring.cpp \
src/httpserverresponse.cpp \
src/httpserverrequestrouter.cpp \
src/httpserverrequest.cpp \
src/httpserver.cpp \
src/httppluginserver.cpp \
src/httpfileserver.cpp \
src/headers.cpp \
src/abstractmessagesocket.cpp \
src/abstracthttpserverrequesthandler.cpp \
src/priv/tcpserverwrapper.cpp \
src/priv/rfc1123.cpp \
src/priv/rfc1036.cpp \
src/priv/reasonphrase.cpp \
src/priv/http_parser.c \
src/priv/asctime.cpp
HEADERS += \
src/websocket.h \
src/url.h \
src/tufao_global.h \
src/simplesessionstore.h \
src/sessionstore.h \
src/sessionsettings.h \
src/session.h \
src/querystring.h \
src/ibytearray.h \
src/httpsserver.h \
src/httpserverresponse.h \
src/httpserverrequestrouter.h \
src/httpserverrequest.h \
src/httppluginserver.h \
src/httpfileserver.h \
src/headers.h \
src/abstractmessagesocket.h \
src/abstracthttpserverrequesthandlerfactory.h \
src/abstracthttpserverrequesthandler.h \
src/priv/websocket.h \
src/priv/url.h \
src/priv/tcpserverwrapper.h \
src/priv/simplesessionstore.h \
src/priv/sessionstore.h \
src/priv/rfc1123.h \
src/priv/rfc1036.h \
src/priv/reasonphrase.h \
src/priv/httpsserver.h \
src/priv/httpserverresponse.h \
src/priv/httpserverrequestrouter.h \
src/priv/httpserverrequest.h \
src/priv/httpserver.h \
src/priv/httppluginserver.h \
src/priv/httpfileserver.h \
src/priv/http_parser.h \
src/priv/cryptography.h \
src/priv/asctime.h
unix:!symbian {
maemo5 {
target.path = /opt/usr/lib
} else {
target.path = /usr/lib
}
INSTALLS += target
}
After build, I get libtufao.a
. So next step is to test it. I created simple test project and added this library by clicking Add library -> external -> static. Open dialog can open only .lib
files so I changed libtufao.a
to libtufao.lib
:
QT += core gui network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = sockettest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h \
FORMS += mainwindow.ui
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../components/tufao-build-Desktop_Qt_5_0_1_MinGW_32bit-Release/release/ -llibtufao
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../components/tufao-build-Desktop_Qt_5_0_1_MinGW_32bit-Release/debug/ -llibtufao
INCLUDEPATH += $$PWD/../../components/tufao/src
DEPENDPATH += $$PWD/../../components/tufao/src
win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../components/tufao-build-Desktop_Qt_5_0_1_MinGW_32bit-Release/release/libtufao.lib
else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../components/tufao-build-Desktop_Qt_5_0_1_MinGW_32bit-Release/debug/libtufao.lib
But when I try to build this test project I get compiler error:
undefined reference to `imp__ZN5Tufao9WebSocket13connectToHostERK12QHostAddresstRK10QByteArrayRKNS_7HeadersE' collect2.exe:-1:
error: ld returned 1 exit status
Can anyone help me?
Regards
EDIT:
Problem solved by adding all sources into my dest project and in .pro
file I added DEFINES += TUFAO_LIBRARY
. Now everything is compiling fine.