Stay organized with collectionsSave and categorize content based on your preferences.
Power up your C++ games with our Firebase C++ SDKs which provide a C++
interface on top of Firebase SDKs.
Access Firebase entirely from your C++ code, without having to write any
platform-native code. The Firebase SDK also translates many language-specific
idioms used by Firebase into an interface more familiar to C++ developers.
Find out more information about powering up your games with Firebase at ourFirebase games page.
Already added Firebase to your C++ project? Make sure that you're using the
latest version of theFirebaseC++SDK.
Prerequisites
Install the following:
Xcode 13.3.1 or later
CocoaPods 1.12.0 or later
Make sure that your project targets the following platform versions or later:
iOS 13
tvOS 13
Set up a physical device or use the simulator to run your app.
Do you want to useCloud Messaging?
ForCloud Messagingon Apple platforms, here are the prerequisites:
Before you can add Firebase to your C++ project, you need to create a Firebase
project to connect to your C++ project. VisitUnderstand Firebase Projectsto learn more about
Firebase projects.
If you create a new account, select yourAnalyticsreporting location, then accept
the data sharing settings andGoogle Analyticsterms for your project.
ClickCreate project(orAdd Firebase, if you're using an
existingGoogle Cloudproject).
Firebase automatically provisions resources for your Firebase project. When
the process completes, you'll be taken to the overview page for your Firebase
project in theFirebaseconsole.
Step 3: Register your app with Firebase
To use Firebase in your Apple app, you need to register your app with your
Firebase project. Registering your app is often called "adding" your app to your
project.
ClickDownload GoogleService-Info.plistto obtain your Firebase Apple
platforms config file.
What do you need to know about this config file?
The Firebase config file contains unique, but non-secret identifiers for
your project. To learn more about this config file, visitUnderstand Firebase
Projects.
To your Podfile, add the Firebase pods that you want to use in your
app.
Analyticsenabled
# Add the Firebase pod forGoogle Analyticspod 'FirebaseAnalytics' # Add the pods for any other Firebase products you want to use in your app
# For example, to useFirebase AuthenticationandFirebase Realtime Databasepod 'FirebaseAuth'
pod 'FirebaseDatabase'
Analyticsnot enabled
# Add the pods for the Firebase products you want to use in your app
# For example, to useFirebase AuthenticationandFirebase Realtime Databasepod 'FirebaseAuth'
pod 'FirebaseDatabase'
Install the pods, then open the.xcworkspacefile in Xcode.
The easiest way to add these frameworks is usually to drag them from aFinderwindow directly into Xcode'sProject Navigatorpane (the
far-left pane, by default; or click the file icon in the top-left of Xcode).
Add the Firebase C++ frameworkfirebase.framework, which isrequiredto use any Firebase product.
Add the framework for each Firebase product that you want to use. For
example, to useFirebase Authentication, addfirebase_auth.framework.
Back in theFirebaseconsole, in the setup workflow, clickNext.
If you addedAnalytics, run your app to send verification to Firebase
that you've successfully integrated Firebase. Otherwise, you can skip this
verification step.
Your device logs will display the Firebase verification that initialization
is complete. If you ran your app on an emulator that has network access,
theFirebaseconsolenotifies you that your app connection is complete.
You’re all set! Your C++ app is registered and configured to use Firebase
products.
Available libraries
Learn more about the C++ Firebase libraries in thereference documentationand in our open-source SDK
release onGitHub.
Each Firebase product has different dependencies. Be sure to add all the
listed dependencies for the desired Firebase product to your Podfile and
C++ project.
Each Firebase product may only support a selection of Apple OS platforms (iOS,
tvOS, etc.). Check which platforms are supported by each library inLearn more about C++ and Firebase.
pod 'FirebaseRemoteConfig', '11.2.0' (recommended)pod 'FirebaseAnalytics', '11.2.0'
Additional information for mobile setup
Method swizzling
On iOS, some application events (such as opening URLs and receiving
notifications) require your application delegate to implement specific
methods. For example, receiving a notification might require your application
delegate to implementapplication:didReceiveRemoteNotification:. Because
each iOS application has its own app delegate, Firebase usesmethod swizzling, which allows the replacement of one method with another,
to attach its own handlers in addition to any that you might have implemented.
TheDynamic LinksandCloud Messaginglibraries need
to attach handlers to the application delegate using method swizzling. If
you're using any of these Firebase products, at load time, Firebase will
identify yourAppDelegateclass and swizzle the required methods onto it,
chaining a call back to your existing method implementation.
Set up a desktop workflow (beta)
When you're creating a game, it's often much easier to test your game on desktop
platforms first, then deploy and test on mobile devices later in development. To
support this workflow, we provide asubset of theFirebaseC++SDKswhich can run on
Windows, macOS, Linux, and from within the C++ editor.
For desktop workflows, you need to complete the following:
Create adesktopversion of the Firebase configuration file:
If you added the Androidgoogle-services.jsonfile— When you run
your app, Firebase locates thismobilefile, then automatically
generates adesktopFirebase config file
(google-services-desktop.json).
If you added the iOSGoogleService-Info.plistfile— Before you run
your app, you need to convert thismobilefile to adesktopFirebase
config file. To convert the file, run the following command from the same
directory as yourGoogleService-Info.plistfile:
This desktop config file contains the C++ project ID that you entered in
theFirebaseconsole setup workflow. VisitUnderstand Firebase Projectsto learn more about config files.
Add Firebase SDKs to your C++ project.
The steps below serve as an example of how to add anysupported Firebase productto
your C++ project. In this example, we walk through addingFirebase AuthenticationandFirebase Realtime Database.
Set yourFIREBASE_CPP_SDK_DIRenvironment variable to the location of
the unzippedFirebaseC++SDK.
To your project'sCMakeLists.txtfile, add the following content,
including thelibrariesfor
the Firebase products that you want to use. For example, to useFirebase AuthenticationandFirebase Realtime Database:
# Add Firebase libraries to the target using the function from the SDK.
add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL)
# The Firebase C++ library `firebase_app` is required,
# and it must always be listed last.
# Add the Firebase SDKs for the products you want to use in your app
# For example, to useFirebase AuthenticationandFirebase Realtime Databaseset(firebase_libs firebase_auth firebase_database firebase_app)
target_link_libraries(${target_name} "${firebase_libs}")
Run your C++ app.
Available libraries (desktop)
TheFirebaseC++SDK includesdesktop workflow supportfor a subset of features, enabling certain parts of Firebase to be used in
standalone desktop builds on Windows, macOS, and Linux.
Firebase provides the remaining desktop libraries as stub (non-functional)
implementations for convenience when building for Windows, macOS, and Linux.
Therefore, you don't need to conditionally compile code to target the desktop.
Realtime Databasedesktop
TheRealtime DatabaseSDK for desktop uses REST to access your database, so you mustdeclare the indexesthat
you use withQuery::OrderByChild()on desktop or your listeners will fail.
Additional information for desktop setup
Windows libraries
For Windows, library versions are provided based on the following:
Build platform: 32-bit (x86) vs 64-bit (x64) mode
Windows runtime environment: Multithreaded / MT vs Multithreaded DLL /MD
Target: Release vs Debug
Note that the following libraries were tested using Visual Studio 2015 and 2017.
When building C++ desktop apps on Windows, link the following Windows SDK
libraries to your project. Consult your compiler documentation for more
information.
For macOS (Darwin), library versions are provided for the 64-bit (x86_64)
platform. Frameworks are also provided for your convenience.
Note that the macOS libraries have been tested using Xcode
13.3.1.
When building C++ desktop apps on macOS, link the following to your project:
pthreadsystem library
CoreFoundationmacOS system framework
FoundationmacOS system framework
SecuritymacOS system framework
GSSmacOS system framework
KerberosmacOS system framework
SystemConfigurationmacOS system framework
Consult your compiler documentation for more information.
Linux libraries
For Linux, library versions are provided for 32-bit (i386) and 64-bit (x86_64)
platforms.
Note that the Linux libraries were tested using GCC 4.8.0, GCC 7.2.0, and
Clang 5.0 on Ubuntu.
When building C++ desktop apps on Linux, link thepthreadsystem library to
your project. Consult your compiler documentation for more information. If
you're building with GCC 5 or later, define-D_GLIBCXX_USE_CXX11_ABI=0.