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 our Firebase games page.
Already added Firebase to your C++ project? Make sure that you're using the latest version of the Firebase C++ 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.
For Cloud Messaging on Apple platforms, here are the prerequisites:
- Set up a physical Apple device.
- Obtain an Apple Push Notification Authentication Key for your Apple Developer account.
- Enable Push Notifications in Xcode under App > Capabilities.
Sign into Firebase using your Google account.
Step 2: Create a Firebase project
Before you can add Firebase to your C++ project, you need to create a Firebase project to connect to your C++ project. Visit Understand Firebase Projects to learn more about Firebase projects.
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.
Go to the Firebase console.
In the center of the project overview page, click the iOS+ icon to launch the setup workflow.
If you've already added an app to your Firebase project, click Add app to display the platform options.
Enter your app's bundle ID in the bundle ID field.
A bundle ID uniquely identifies an application in Apple's ecosystem.
Find your bundle ID: open your project in Xcode, select the top-level app in the project navigator, then select the General tab.
The value of the Bundle Identifier field is the bundle ID (for example,
com.yourcompany.yourproject
).Be aware that the bundle ID value is case-sensitive, and it cannot be changed for this Firebase app after it's registered with your Firebase project.
(Optional) Enter other app information: App nickname and App Store ID.
App nickname: An internal, convenience identifier that is only visible to you in the Firebase console
App Store ID: Used by Firebase Dynamic Links to redirect users to your App Store page and by Google Analytics to import conversion events into Google Ads. If your app doesn't yet have an App Store ID, you can add the ID later in your Project settings.
Click Register app.
Step 4: Add the Firebase configuration file
Click Download GoogleService-Info.plist to obtain your Firebase Apple platforms config file.
The Firebase config file contains unique, but non-secret identifiers for your project. To learn more about this config file, visit Understand Firebase Projects.
You can download your Firebase config file again at any time.
Make sure the config file name is not appended with additional characters, like
(2)
.
Open your C++ project in an IDE, then drag your config file into the root of your C++ project.
If prompted, select to add the config file to all targets.
You're done with set up tasks in the Firebase console. Continue to Add Firebase C++ SDKs below.
Step 5: Add Firebase C++ SDKs
The steps in this section are an example of how to add supported Firebase products to your Firebase C++ project.
Download the Firebase C++ SDK, then unzip the SDK somewhere convenient.
The Firebase C++ SDK is not platform-specific, but it does contain platform-specific libraries.
Add Firebase pods from the unzipped SDK.
Create a Podfile if you don't already have one:
cd your-app-directory
pod init
To your Podfile, add the Firebase pods that you want to use in your app.
Analytics enabled
# Add the Firebase pod for Google Analytics pod 'FirebaseAnalytics'
# Add the pods for any other Firebase products you want to use in your app # For example, to use Firebase Authentication and Firebase Realtime Database pod 'FirebaseAuth' pod 'FirebaseDatabase'Analytics not enabled
# Add the pods for the Firebase products you want to use in your app # For example, to use Firebase Authentication and Firebase Realtime Database pod 'FirebaseAuth' pod 'FirebaseDatabase'
Install the pods, then open the
.xcworkspace
file in Xcode.pod install
open your-app.xcworkspace
Add Firebase frameworks from the unzipped SDK.
The easiest way to add these frameworks is usually to drag them from a
Finder
window directly into Xcode's Project Navigator pane (the far-left pane, by default; or click the file icon in the top-left of Xcode).Add the Firebase C++ framework
firebase.framework
, which is required to use any Firebase product.Add the framework for each Firebase product that you want to use. For example, to use Firebase Authentication, add
firebase_auth.framework
.
Back in the Firebase console, in the setup workflow, click Next.
If you added Analytics, 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, the Firebase console notifies 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 the reference documentation and in our open-source SDK release on GitHub.
Available libraries for Apple platforms
Note that C++ libraries for Android are listed on the Android version of this setup page.
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 in Learn more about C++ and Firebase.
Firebase product | Frameworks and Pods |
---|---|
AdMob |
(required) firebase.framework firebase_admob.framework (required) firebase_analytics.framework pod 'FirebaseAdMob', '11.2.0' (required) pod 'FirebaseAnalytics', '11.2.0'
|
Analytics |
(required) firebase.framework firebase_analytics.framework pod 'FirebaseAnalytics', '11.2.0'
|
App Check |
(required) firebase.framework firebase_app_check.framework pod 'FirebaseAppCheck', '11.2.0'
|
Authentication |
(required) firebase.framework firebase_auth.framework pod 'FirebaseAuth', '11.2.0'
|
Cloud Firestore |
(required) firebase.framework firebase_firestore.framework firebase_auth.framework pod 'FirebaseFirestore', '11.2.0' pod 'FirebaseAuth', '11.2.0'
|
Cloud Functions |
(required) firebase.framework firebase_functions.framework pod 'FirebaseFunctions', '11.2.0'
|
Cloud Messaging |
(required) firebase.framework firebase_messaging.framework (recommended) firebase_analytics.framework pod 'FirebaseMessaging', '11.2.0' (recommended) pod 'FirebaseAnalytics', '11.2.0'
|
Cloud Storage |
(required) firebase.framework firebase_storage.framework pod 'FirebaseStorage', '11.2.0'
|
Dynamic Links |
(required) firebase.framework firebase_dynamic_links.framework (recommended) firebase_analytics.framework pod 'FirebaseDynamicLinks', '11.2.0' (recommended) pod 'FirebaseAnalytics', '11.2.0'
|
Realtime Database |
(required) firebase.framework firebase_database.framework pod 'FirebaseDatabase', '11.2.0'
|
Remote Config |
(required) firebase.framework firebase_remote_config.framework (recommended) firebase_analytics.framework 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 implement application:didReceiveRemoteNotification:
. Because
each iOS application has its own app delegate, Firebase uses
method swizzling, which allows the replacement of one method with another,
to attach its own handlers in addition to any that you might have implemented.
The Dynamic Links and Cloud Messaging libraries 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 your AppDelegate
class 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 a subset of the Firebase C++ SDKs which can run on Windows, macOS, Linux, and from within the C++ editor.
For desktop workflows, you need to complete the following:
- Configure your C++ project for CMake.
- Create a Firebase project
- Register your app (iOS or Android) with Firebase
- Add a mobile-platform Firebase configuration file
Create a desktop version of the Firebase configuration file:
If you added the Android
google-services.json
file — When you run your app, Firebase locates this mobile file, then automatically generates a desktop Firebase config file (google-services-desktop.json
).If you added the iOS
GoogleService-Info.plist
file — Before you run your app, you need to convert this mobile file to a desktop Firebase config file. To convert the file, run the following command from the same directory as yourGoogleService-Info.plist
file:generate_xml_from_google_services_json.py --plist -i GoogleService-Info.plist
This desktop config file contains the C++ project ID that you entered in the Firebase console setup workflow. Visit Understand Firebase Projects to learn more about config files.
Add Firebase SDKs to your C++ project.
The steps below serve as an example of how to add any supported Firebase product to your C++ project. In this example, we walk through adding Firebase Authentication and Firebase Realtime Database.
Set your
FIREBASE_CPP_SDK_DIR
environment variable to the location of the unzipped Firebase C++ SDK.To your project's
CMakeLists.txt
file, add the following content, including the libraries for the Firebase products that you want to use. For example, to use Firebase Authentication and Firebase 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 use Firebase Authentication and Firebase Realtime Database set(firebase_libs firebase_auth firebase_database firebase_app) target_link_libraries(${target_name} "${firebase_libs}")
Run your C++ app.
Available libraries (desktop)
The Firebase C++ SDK includes desktop workflow support for a subset of features, enabling certain parts of Firebase to be used in standalone desktop builds on Windows, macOS, and Linux.
Firebase product | Library references (using CMake) |
---|---|
App Check |
firebase_app_check (required) firebase_app
|
Authentication |
firebase_auth (required) firebase_app
|
Cloud Firestore |
firebase_firestore firebase_auth firebase_app
|
Cloud Functions |
firebase_functions (required) firebase_app
|
Cloud Storage |
firebase_storage (required) firebase_app
|
Realtime Database |
firebase_database (required) firebase_app
|
Remote Config |
firebase_remote_config (required) firebase_app
|
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 Database desktop
The Realtime Database SDK for desktop uses REST to access your database, so you must
declare the indexes that
you use with Query::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.
Firebase C++ Library | Windows SDK library dependencies |
---|---|
App Check | advapi32, ws2_32, crypt32 |
Authentication | advapi32, ws2_32, crypt32 |
Cloud Firestore | advapi32, ws2_32, crypt32, rpcrt4, ole32, shell32 |
Cloud Functions | advapi32, ws2_32, crypt32, rpcrt4, ole32 |
Cloud Storage | advapi32, ws2_32, crypt32 |
Realtime Database | advapi32, ws2_32, crypt32, iphlpapi, psapi, userenv |
Remote Config | advapi32, ws2_32, crypt32, rpcrt4, ole32 |
macOS libraries
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:
pthread
system libraryCoreFoundation
macOS system frameworkFoundation
macOS system frameworkSecurity
macOS system frameworkGSS
macOS system frameworkKerberos
macOS system frameworkSystemConfiguration
macOS 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 the pthread
system 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
.
Next steps
Explore sample Firebase apps.
Explore the open source SDK in GitHub.
Prepare to launch your app:
- Set up budget alerts for your project in the Google Cloud console.
- Monitor the Usage and billing dashboard in the Firebase console to get an overall picture of your project's usage across multiple Firebase services.
- Review the Firebase launch checklist.