El SDK de Atlas Device para C++ permite a las aplicaciones cliente escritas en C++ acceder a los datos almacenados en los dispositivos y sincronizar datos con Atlas. Esta página detalla cómo instalar el SDK de C++ en tu Proyecto y empezar a usarlo.
Requisitos
Estándar mínimo de C++: C++17.
Para desarrollo en macOS: Xcode 11.x o posterior.
For development on Windows: Microsoft Visual C++ (MSVC).
De lo contrario, recomendamos git y CMake.
Instalar
Tip
Atlas Device SDK and Realm
El SDK utiliza la base de datos Realm Core para la persistencia de los datos del dispositivo. Al instalar el SDK de C++, los nombres de los paquetes reflejan la nomenclatura de Realm.
Al desarrollar con Xcode, puedes usar Swift Package Manager (SPM) para instalar realm-cpp.
Puede utilizar CMake con el módulo FetchContent para administrar el SDK y sus dependencias en su proyecto C++.
Crea o modifica tu CMakeLists.txt en el directorio raíz de tu proyecto:
Agrega
Include(FetchContent)para incluir el módulo FetchContent en la compilación de tu proyecto.Utilice
FetchContent_Declarepara localizar la dependencia del SDK y especificar la etiqueta de versión que desea utilizar.Utilice el comando
FetchContent_MakeAvailable()para verificar si se han completado las dependencias nombradas y, si no es así, completarlas.Finalmente,
target_link_libraries()vincula la dependencia del SDK a su ejecutable de destino.
To get the most recent version tag, refer to the releases on GitHub: realm/realm-cpp.
Set the minimum C++ standard to 17 with set(CMAKE_CXX_STANDARD 17).
In a Windows install, add the required compiler flags listed below.
cmake_minimum_required(VERSION 3.15) project(MyDeviceSDKCppProject) # Minimum C++ standard set(CMAKE_CXX_STANDARD 17) # In a Windows install, set these compiler flags: if(MSVC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:preprocessor /bigobj") endif() # Include the FetchContent module so you can download the C++ SDK Include(FetchContent) # Declare the version of the C++ SDK you want to download FetchContent_Declare( cpprealm GIT_REPOSITORY https://github.com/realm/realm-cpp.git GIT_TAG v1.0.0 ) # The MakeAvailable command ensures the named dependencies have been populated FetchContent_MakeAvailable(cpprealm) # Create an executable target called myApp with the source file main.cpp add_executable(myApp main.cpp) target_link_libraries(myApp PRIVATE cpprealm)
Ejecute CMake en un directorio gitignored, como build, para generar las configuraciones de compilación que luego puede usar para compilar su aplicación:
# build/ is in .gitignore mkdir build cd build cmake .. # Create Makefile by reading the CMakeLists.txt in the parent directory (../) make # Actually build the app
You can use CMake to generate more than simple Makefiles by using the -G flag. See the CMake documentation for more information.
Uso
Include the Header
Make the C++ SDK available in your code by including the cpprealm/sdk.hpp header in the translation unit where you want to use it:
Compila una aplicación Android
The C++ SDK supports building Android apps. To build an Android app:
Add
<uses-permission android:name="android.permission.INTERNET" />to yourAndroidManifest.xmlAgregue el subdirectorio del SDK de C++ a
CMakeLists.txtde su biblioteca nativa y vincúlelo como una biblioteca de destino:set(CMAKE_CXX_STANDARD 17) add_subdirectory("realm-cpp") ... target_link_libraries( # Specifies the target library. myapplication # make sure to link the C++ SDK. cpprealm ) Ensure that the git submodules are initialized inside of the
realm-cppfolder before building.When instantiating the database or the SDK App, you must pass the
filesDir.pathas thepathparameter in the respective constructor or database open template.
Para ver un ejemplo de cómo usar el C++ SDK en una aplicación Android, consulta la aplicación Android RealmExample en el repositorio de GitHub realm-cpp.
Específicamente, consulte los archivos MainActivity.kt y native-lib.cpp en la aplicación de ejemplo de Android para obtener ejemplos de código.