我是 C++ 编程的新手。我从 Qt 5.0.1 开始。我需要使用来自:https ://code.google.com/p/tufao/ 的 WebSockets,但我没有安装 MinGW,所以我用谷歌搜索我可以创建 Qt 库项目,包含这些源文件并构建静态库。所以我做到了:
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
}
构建后,我得到libtufao.a
. 所以下一步是测试它。我创建了简单的测试项目并通过单击添加库-> 外部-> 静态添加了这个库。打开对话框只能打开.lib
文件,所以我libtufao.a
改为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
但是当我尝试构建这个测试项目时,我得到了编译器错误:
未定义的引用` imp __ZN5Tufao9WebSocket13connectToHostERK12QHostAddresstRK10QByteArrayRKNS_7HeadersE' collect2.exe:-1:
错误:ld 返回 1 个退出状态
谁能帮我?
问候
编辑:
通过将所有源添加到我的 dest 项目和.pro
我添加的文件中解决了问题DEFINES += TUFAO_LIBRARY
。现在一切都编译好了。