问题描述
我在构建示例应用程序时遇到链接错误,这个 (https://github.com/tdlib/td/blob/master/example/cpp/td_example.cpp) 我在 Qt creator 中创建了项目并将 td_example.cpp 添加到项目中。之前我也使用此指令从源代码构建了 32x Td 库 https://tdlib.github.io/td/build.html?language=C%2B%2B .
位于此路径 K:\QtProjects\Telegram\TelegramDependency\td\tdlib 中的 Td 工件, 这里有 3 个文件夹(bin、include 和 lib)。
位于 bin 文件夹中的 4 个 .dll 文件(libcrypto-1_1.dll、libssl-1_1.dll、tdjson.dll、zlibd1.dll)
位于 lib 文件夹中(tdactor.lib、tdapi.lib、tdclient.lib、tdcore.lib、tddb.lib、tdjson.lib、tdjson_private.lib、tdjson_static.lib、tdnet.lib、tdsqlite.lib、tdutils。库)
我的项目位于此路径下 K:\QtProjects\Telegram\TelegramTestAPP
在 TelegramTestAPP 文件夹中,我有包含此类内容的 .pro 文件。
QT += quick
CONfig += c++20
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so,uncomment the following line.
#DEFInes += QT_disABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
Logger.cpp \
main.cpp \
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \
Logger.h \
td_example.h
win32: LIBS += -L'$$PWD/../TelegramDependency/td/tdlib/lib/' -ltdjson
INCLUDEPATH += $$PWD/../TelegramDependency/td/tdlib/include
DEPENdpath += $$PWD/../TelegramDependency/td/tdlib/include
我从 td_example.cpp 中删除了 main 函数并重命名为 td_example.h ,之后我包含了这个头文件并从 main.cpp 中的 main 函数中调用了它
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "td_example.h"
int main(int argc,char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6,0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QGuiApplication app(argc,argv);
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty(QStringLiteral("CLogger"),&Logger::GetInstance());
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine,&QQmlApplicationEngine::objectCreated,&app,[url](QObject *obj,const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
},Qt::QueuedConnection);
engine.load(url);
TdExample example;
example.loop();
return app.exec();
}
main.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall td::td_api::tdlibParameters::tdlibParameters(void)" (??0tdlibParameters@td_api@td@@QAE@XZ) referenced in function "class td::tl::unique_ptr<class td::td_api::tdlibParameters> __cdecl td::td_api::make_object<class td::td_api::tdlibParameters>(void)" (??$make_object@VtdlibParameters@td_api@td@@$$V@td_api@td@@YA?AV?$unique_ptr@VtdlibParameters@td_api@td@@@tl@1@XZ)
编译器:Microsoft Visual C++ 编译器 14.0 (amd64_x86) 我还将所有 .dll 从 bin 文件夹复制到调试文件夹(TelegramTestAPP/build/debug)
win32: LIBS += -L'$$PWD/../TelegramDependency/td/tdlib/lib/' -ltdapi
win32: LIBS += -L'$$PWD/../TelegramDependency/td/tdlib/lib/' -ltdutils
win32: LIBS += -L'$$PWD/../TelegramDependency/td/tdlib/lib/' -ltdclient
win32: LIBS += -L'$$PWD/../TelegramDependency/td/tdlib/lib/' -ltdnet
win32: LIBS += -L'$$PWD/../TelegramDependency/td/tdlib/lib/' -ltdcore
win32: LIBS += -L'$$PWD/../TelegramDependency/td/tdlib/lib/' -ltdsqlite
win32: LIBS += -L'$$PWD/../TelegramDependency/td/tdlib/lib/' -ltdactor
win32: LIBS += -L'$$PWD/../TelegramDependency/td/tdlib/lib/' -ltddb
INCLUDEPATH += $$PWD/../TelegramDependency/td/tdlib/include
DEPENdpath += $$PWD/../TelegramDependency/td/tdlib/include
win32: PRE_TARGETDEPS += $$PWD/../TelegramDependency/td/tdlib/lib/tdcore.lib
win32: PRE_TARGETDEPS += $$PWD/../TelegramDependency/td/tdlib/lib/tdapi.lib
win32: PRE_TARGETDEPS += $$PWD/../TelegramDependency/td/tdlib/lib/tdclient.lib
win32: PRE_TARGETDEPS += $$PWD/../TelegramDependency/td/tdlib/lib/tdutils.lib
win32: PRE_TARGETDEPS += $$PWD/../TelegramDependency/td/tdlib/lib/tdactor.lib
win32: PRE_TARGETDEPS += $$PWD/../TelegramDependency/td/tdlib/lib/tddb.lib
win32: PRE_TARGETDEPS += $$PWD/../TelegramDependency/td/tdlib/lib/tdnet.lib
win32: PRE_TARGETDEPS += $$PWD/../TelegramDependency/td/tdlib/lib/tdsqlite.lib
win32: LIBS += -L'C:/Program Files (x86)/OpenSSL-Win32/lib/VC/' -llibcrypto32MDd
win32: LIBS += -L'C:/Program Files (x86)/OpenSSL-Win32/lib/VC/' -llibssl32MDd
INCLUDEPATH += 'C:/Program Files (x86)/OpenSSL-Win32/include'
DEPENdpath += 'C:/Program Files (x86)/OpenSSL-Win32/include'
新错误(编译器 gcc 32 位)
error: undefined reference to `td::ClientManager::execute(td::tl::unique_ptr<td::td_api::Function>&&)'
debug/TdController.o: In function `ZN12TdControllerC2Ev':
error: undefined reference to `td::td_api::setLogVerbosityLevel::setLogVerbosityLevel(int)'
debug/TdController.o: In function `ZN2td6td_api11make_objectINS0_20setLogVerbosityLevelEJiEEENS_2tl10unique_ptrIT_EEDpOT0_':
error: undefined reference to `vtable for td::td_api::setLogVerbosityLevel'
debug/TdController.o: In function `ZN2td6td_api20setLogVerbosityLevel
D1Ev':
解决方法
我不知道那些库,但根据此 https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1tdlib_parameters-members.html,您缺少的符号来自 td_api,它似乎没有链接。您是否尝试链接到其他库,特别是 tdapi.lib?