2

I am trying to import a library that i installed using vcpkg (vcpkg install azure-storage-blobs-cpp)

In my c++ file I am trying to import azure/storage/blobs.hpp

In my vcpkg directory, i have the following file

./installed/x64-osx/include/azure/storage/blobs.hpp
./packages/azure-storage-blobs-cpp_x64-osx/include/azure/storage/blobs.hpp

vcpkg install azure-storage-blobs-cpp returns

azure-storage-blobs-cpp provides CMake targets:
    # this is heuristically generated, and may not be correct
    find_package(azure-storage-blobs-cpp CONFIG REQUIRED)
    target_link_libraries(main PRIVATE Azure::azure-storage-blobs)

Here is my cpp file

    #include <iostream>
    #include <azure/storage/blobs.hpp>
    int main() {
            std::cout<<"Hello CMake!"<<std::endl;
            return 0;
    }

Here is my CMAKE file

    cmake_minimum_required(VERSION 3.9.1)
    project(CMakeHello)
    set(CMAKE_CXX_STANDARD 14)

    find_package(azure-storage-blobs-cpp CONFIG REQUIRED)
    target_link_libraries(main PRIVATE Azure::azure-storage-blobs)
    add_executable(cmake_hello azuretest.cpp)

but i am reaching

CMake Error at CMakeLists.txt:7 (find_package):
  Could not find a package configuration file provided by
  "azure-storage-blobs-cpp" with any of the following names:

    azure-storage-blobs-cppConfig.cmake
    azure-storage-blobs-cpp-config.cmake

  Add the installation prefix of "azure-storage-blobs-cpp" to
  CMAKE_PREFIX_PATH or set "azure-storage-blobs-cpp_DIR" to a directory
  containing one of the above files.  If "azure-storage-blobs-cpp" provides a
  separate development package or SDK, be sure it has been installed.

after cmake CMakeLists.txt

How do I import azure/storage/blobs.hpp?

This is in mac environment

Kevin
  • 75
  • 6

1 Answers1

1

You need to use:

-DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake

while configuring your cmake. You can see full guide here. So you need to first correct your cmake as follows:

cmake_minimum_required(VERSION 3.9.1)
project(CMakeHello)
set(CMAKE_CXX_STANDARD 14)

find_package(azure-storage-blobs-cpp CONFIG REQUIRED)

add_executable(cmake_hello azuretest.cpp)
target_link_libraries(cmake_hello PRIVATE Azure::azure-storage-blobs)

then run following commands in your source directory:

cmake -B ./build -S . -DCMAKE_TOOLCHAIN_FILE=[path_to_vcpkg]/scripts/buildsystems/vcpkg.cmake
cmake --build ./build

remember to replace [path_to_vcpkg] with real path.

Afshin
  • 8,839
  • 1
  • 18
  • 53
  • I tried `cmake CMakeLists.txt -DCMAKE_TOOLCHAIN_FILE=/path_to_vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake ` and `cmake -B ./ -S . -DCMAKE_TOOLCHAIN_FILE=/path_to_vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake ` still same issue, note i replace path_to_vcpkg with actual path – Kevin Jul 27 '22 at 04:45
  • what is build directory in this case for `cmake -B [build directory] -S . -DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake ` , the directory my cmake file is at? – Kevin Jul 27 '22 at 04:46
  • @Kevin `-B` shows build directory where cmake cache will be created. `-S` is source directory where your `CMakeLists.txt` is. So you need something like `cmake -B ./build -S . -DCMAKE_TOOLCHAIN_FILE=/path_to_vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake` to configure project and then `cmake --build ./build` to build it. – Afshin Jul 27 '22 at 04:49
  • thanks it works after i define a new build directory – Kevin Jul 27 '22 at 04:54