简体   繁体   中英

Qt && firebase C++ SDK linking issues on iOS

I have following build env:

  • host: OSX 10.12 Sierra
  • XCode 9.2
  • Qt 5.10.1 for iOS
  • QtCreator 4.7.0
  • firebase 5.2

and try to build my application from QtCreator for iOS with the firebase support, but it fails with following linking errors:

Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_FIRMessaging", referenced from: objc-class-ref in firebase_messaging(messaging_231c52c311096cfce13e67fa91eb9ac5.o)
"_OBJC_CLASS_$_FIRApp", referenced from: objc-class-ref in firebase(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)

I have simplified my project to following code:

== main.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_cpp_sdk/frameworks/ios/universal
  • ~/firebase_cpp_sdk/frameworks/ios/amd64
  • ~/firebase_cpp_sdk/frameworks/ios/i386
  • ~/firebase_cpp_sdk/frameworks/ios/x86_64
  • ~/firebase_cpp_sdk/frameworks/ios/armv7

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.

Also I tried to build the project from the XCode, using qmake's generated xcode.project file, but there are same error.

I looked on stackoverflow a similar issues, but that workarounds does not help:

  • I tried to remove the /Users/admin/Library/Developer/Xcode/DerivedData directory.
  • I tried to play with the XCode options "Build Settings -> Build Active Architecture Only -> yes|no"

I looked a code from the following projects:

But I don't understand why this linker error happens.. Maybe is it a qmake bug?

The error means the project lacks Firebase pod.

firebase_cpp_sdk alone is not enough, in addition, it requires Firebase Core library.

In order add Firebase lib, you should migrate to use cocoapods.

In the project's source root, run pod init a new file Podfile would be then generated.

Open the file, add the following line to the target pod 'Firebase/Analytics' and save the file.

After running pod update successfully, open the .xcworkspace and build as usual.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM