[英]Qt && firebase C++ SDK linking issues on iOS
I have following build env:我有以下构建环境:
and try to build my application from QtCreator for iOS with the firebase support, but it fails with following linking errors:并尝试使用 firebase 支持从 QtCreator 为 iOS 构建我的应用程序,但它失败并出现以下链接错误:
Undefined symbols for architecture arm64:架构 arm64 的未定义符号:
"_OBJC_CLASS_$_FIRMessaging", referenced from: objc-class-ref in firebase_messaging(messaging_231c52c311096cfce13e67fa91eb9ac5.o) “_OBJC_CLASS_$_FIRMessaging”,引用自:firebase_messaging 中的 objc-class-ref(messaging_231c52c311096cfce13e67fa91eb9ac5.o)
"_OBJC_CLASS_$_FIRApp", referenced from: objc-class-ref in firebase(app_ios_814e1620d4f88024cea4bade26623a67.o) “_OBJC_CLASS_$_FIRApp”,引用自:firebase 中的 objc-class-ref(app_ios_814e1620d4f88024cea4bade26623a67.o)
"_OBJC_CLASS_$_FIROptions", referenced from: objc-class-ref in firebase(app_ios_814e1620d4f88024cea4bade26623a67.o) ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) “_OBJC_CLASS_$_FIROptions”,引用自:firebase 中的 objc-class-ref(app_ios_814e1620d4f88024cea4bade26623a67.o) ld:未找到体系结构 arm64 的符号 clang:错误:linker 命令失败,退出代码 1(使用 -v )
I have simplified my project to following code:我已将我的项目简化为以下代码:
== main.cpp == == 主.cpp ==
#include <QCoreApplication>
#include <firebase/app.h>
#include <firebase/messaging.h>
#include <firebase/util.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
::firebase::App *fapp = ::firebase::App::Create();
Q_UNUSED(fapp);
return a.exec();
}
and a project file is:项目文件是:
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
# Check for GOOGLE_FIREBASE_SDK environment variable.
ENV_GOOGLE_FIREBASE_SDK = $$(GOOGLE_FIREBASE_SDK)
# Or define GOOGLE_FIREBASE_SDK path here.
GOOGLE_FIREBASE_SDK =
isEmpty(ENV_GOOGLE_FIREBASE_SDK) {
isEmpty(GOOGLE_FIREBASE_SDK) {
message("GOOGLE_FIREBASE_SDK" environment variable not detected!)
}
}
INCLUDEPATH += $$(GOOGLE_FIREBASE_SDK)
INCLUDEPATH += $$(GOOGLE_FIREBASE_SDK)/include
SOURCES += \
main.cpp
FCM_LIBS_PATH = $$(GOOGLE_FIREBASE_SDK)/frameworks/ios/universal
message("FCM_LIBS_PATH = $$FCM_LIBS_PATH")
LIBS += -F$$FCM_LIBS_PATH \
-framework firebase_messaging \
-framework firebase \
-framework Foundation \
-framework UserNotifications \
-framework UIKit \
-framework CoreGraphics
The firebase SDK contains different frameworks directories for different architectures: firebase SDK 包含不同架构的不同框架目录:
As I see that error related to 'arm64' architecture, so, I have changed the project file LIBS to use 'arm64' instead of 'universal', but this does not help.正如我所看到的与“arm64”架构相关的错误,因此,我已将项目文件 LIBS 更改为使用“arm64”而不是“universal”,但这无济于事。
Also I tried to build the project from the XCode, using qmake's generated xcode.project file, but there are same error.我还尝试使用 qmake 生成的 xcode.project 文件从 XCode 构建项目,但出现相同的错误。
I looked on stackoverflow a similar issues, but that workarounds does not help:我在 stackoverflow 上查看了类似的问题,但解决方法无济于事:
I looked a code from the following projects:我查看了以下项目的代码:
But I don't understand why this linker error happens.. Maybe is it a qmake bug?但我不明白为什么会出现这个 linker 错误。也许是 qmake 错误?
The error means the project lacks Firebase pod.该错误表示该项目缺少 Firebase pod。
firebase_cpp_sdk
alone is not enough, in addition, it requires Firebase Core library.光有firebase_cpp_sdk
是不够的,另外还需要Firebase核心库。
In order add Firebase lib, you should migrate to use cocoapods.为了添加 Firebase 库,您应该迁移到使用 cocoapods。
In the project's source root, run pod init
a new file Podfile
would be then generated.在项目的源代码根目录中,运行pod init
将生成一个新文件Podfile
。
Open the file, add the following line to the target pod 'Firebase/Analytics'
and save the file.打开文件,将以下行添加到目标pod 'Firebase/Analytics'
并保存文件。
After running pod update
successfully, open the .xcworkspace
and build as usual.成功运行pod update
后,打开.xcworkspace
并照常构建。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.