This month, the Azure SDK team released the new Azure SDK for C++, starting with Azure Core, Identity, and Storage Blobs, Files Shares, and Datalake. We’re excited to share our guides to getting started and working with the latest libraries!
Getting the latest libraries
You can find all of the latest source code on the official Azure SDK for C++ repository. Additionally, the following packages are available to install via vcpkg:
Name | Latest Version | Replaces |
---|---|---|
azure-core-cpp | 1.0.0 | – |
azure-identity-cpp | 1.0.0 | – |
auzre-storage-common-cpp | 12.0.0 | azure-storage-cpp 7.5.0 |
azure-storage-blobs-cpp | 12.0.0 | azure-storage-cpp 7.5.0 |
azure-storage-files-shares-cpp | 12.0.0 | azure-storage-cpp 7.5.0 |
azure-storage-files-datalake-cpp | 12.0.0 | azure-storage-cpp 7.5.0 |
Similar to the Azure SDKs for .NET, Java, JavaScript/TypeScript, and Python, the latest Azure SDK for C++ is divided into smaller libraries that allow for greater control when linking and developing.
At this time, we maintain support for desktop triplets, including:
- x86-windows
- x64-windows
- x64-linux
- x64-osx
Installing the Azure Storage library
Downloading the Azure Storage Blobs, Files Shares, and Datalake libraries through vcpkg is as simple as running the following command:
vcpkg install azure-storage-blobs-cpp[:<triplet>] azure-storage-files-shares-cpp[:<triplet>] azure-storage-files-datalake-cpp:[:<triplet>]
Alternatively, developers are welcome to download source code from the Azure SDK for C++ repository and compile the code directly using the provided CMAKE files.
Getting Started with Azure Storage for C++
The Azure SDK for C++ supports linking with CMAKE by including the following lines in your CMakeLists.txt
file:
find_package(azure-storage-blobs-cpp CONFIG REQUIRED)
target_link_libraries(<your project name> PRIVATE Azure::azure-storage-blobs)
find_package(azure-storage-files-shares-cpp CONFIG REQUIRED)
target_link_libraries(<your project name> PRIVATE Azure::azure-storage-files-shares)
find_package(azure-storage-datalake-cpp CONFIG REQUIRED)
target_link_libraries(<your project name> PRIVATE Azure::azure-storage-datalake)
Listing blobs in a container
The following snippet creates a BlobContainerClient
, which connects with the Azure Storage service, and then lists the blobs in a container using the containerClient
object. Note that in this snippet, the connection string is a secret that has been stored in an environment variable and should not be shared.
#include <azure/storage/blobs.cpp>
using namespace Azure::Storage::Blobs;
std::string connectionString = std::get_env("AZURE_STORAGE_CONNECTION_STRING");
std::string containerName = "mycontainer";
BlobContainerClient containerClient = BlobContainerClient::CreateFromConnectionString(connectionString, containerName);
auto listBlobsResponse = containerClient.ListBlobs();
for (auto blobItem : listBlobsResponse.Blobs)
{
std::cout << "Blob name: " << blobItem.Name << std::endl;
}
Uploading a file to an Azure Files Share
To upload a file to the files share, we create a ShareClient
, which connects with the Azure Storage service, and then a ShareFileClient
to upload the file contents. Note again, in this snippet the connection string has been stored in an environment variable.
#include <azure/storage/files/shares.hpp>
using namespace Azure::Storage::Files::Shares;
std::string connectionString = std::get_env("AZURE_STORAGE_CONNECTION_STRING");
std::string shareName = "myshare";
std::string fileName = "myfile";
std::string fileContent = "Hello Azure!";
auto shareClient = ShareClient::CreateFromConnectionString(connectionString, shareName);
shareClient.CreateIfNotExists();
ShareFileClient fileClient = shareClient.GetRootDirectoryClient().GetFileClient(fileName);
fileClient.UploadFrom(reinterpret_cast<const uint8_t*>(fileContent.data()), fileContent.size());
More Samples
To see a full scenario for the Azure SDKs for C++, visit the official Azure SDK for C++ repository or go to Microsoft Docs. To get you started quickly, you can visit the following quickstarts and samples:
SDK | Quickstart on Docs | Samples on GitHub |
---|---|---|
azure-storage-blobs-cpp | Quickstart | GitHub |
azure-storage-files-shares-cpp | QuickStart | GitHub |
azure-storage-files-datalake-cpp | – | GitHub |
Consistent and Idiomatic
Developers familiar with our other Azure Storage libraries might notice the recurrence of the Azure::Storage::Blobs::BlobContainerClient or Azure::Storage::Files::Shares::ShareClient classes. In accordance with our General Guidelines, we aim for a developer experience that is both consistent with the Azure Storage libraries for our currently released libraries as well as idiomatic to the C++ standards so that developers are supported regardless of the programming language.
Support, Feedback, Feature Requests, and Bug Reporting
The easiest way to get in touch with our development team is to open an issue on the official Azure SDK for C++ repository. We regularly triage new issues; for more information about our GitHub process, check out Lily Ma’s blog post Azure SDK GitHub Support Process.
Azure SDK Blog Contributions
Thank you for reading this Azure SDK blog post! We hope that you learned something new and welcome you to share this post. We are open to Azure SDK blog contributions. Please contact us at azsdkblog@microsoft.com with your topic and we’ll get you set up as a guest blogger.
Azure SDK Links
- Azure SDK Website: aka.ms/azsdk
- Azure SDK Intro (3 minute video): aka.ms/azsdk/intro
- Azure SDK Intro Deck (PowerPoint deck): aka.ms/azsdk/intro/deck
- Azure SDK Releases: aka.ms/azsdk/releases
- Azure SDK Blog: aka.ms/azsdk/blog
- Azure SDK Twitter: twitter.com/AzureSDK
- Azure SDK Design Guidelines: aka.ms/azsdk/guide
- Azure SDKs & Tools: azure.microsoft.com/downloads
- Azure SDK Central Repository: github.com/azure/azure-sdk
- Azure SDK for .NET: github.com/azure/azure-sdk-for-net
- Azure SDK for Java: github.com/azure/azure-sdk-for-java
- Azure SDK for Python: github.com/azure/azure-sdk-for-python
- Azure SDK for JavaScript/TypeScript: github.com/azure/azure-sdk-for-js
- Azure SDK for Android: github.com/Azure/azure-sdk-for-android
- Azure SDK for iOS: github.com/Azure/azure-sdk-for-ios
- Azure SDK for Go: github.com/Azure/azure-sdk-for-go
- Azure SDK for C: github.com/Azure/azure-sdk-for-c
- Azure SDK for C++: github.com/Azure/azure-sdk-for-cpp
0 comments