Azure / azure-storage-cpp

Microsoft Azure Storage Client Library for C++
http://azure.github.io/azure-storage-cpp
Apache License 2.0
131 stars 147 forks source link

Unresolved external symbols when linking to azure-storage-cpp in CMake via VCPkg #339

Closed zachhilman closed 4 years ago

zachhilman commented 4 years ago

I installed azure-storage-cpp via vcpkg, and am using it in a cmake project with the following buildscript to add the library:

find_path(AZURESTORAGE_INCLUDE_DIRS was/blob.h REQUIRED)
find_library(AZURESTORAGE_LIBRARIES azurestorage REQUIRED)

add_library(AzureStorage STATIC IMPORTED GLOBAL)
set_target_properties(AzureStorage PROPERTIES IMPORTED_LOCATION ${AZURESTORAGE_LIBRARIES})
target_include_directories(AzureStorage INTERFACE ${AZURESTORAGE_INCLUDE_DIRS})

However, when I go to compile/link my executable, I get undefined reference errors to what seems to be web functions, boost, xml, uuid, amongst others.

Am I missing additional target_link_library commands? If so, what libraries. Additionally, would it be possible to provide a cmake .config file to make linking easier?

[This was WSL Ubuntu 18.04]

Thanks

Jinming-Hu commented 4 years ago

Hi @DarkLordZach

you have to add dependencies like cpprestsdk manually, can you give this a try?

find_path(AZURESTORAGE_INCLUDE_DIRS was/blob.h REQUIRED)
find_library(AZURESTORAGE_LIBRARIES azurestorage REQUIRED)
find_package(cpprestsdk CONFIG REQUIRED)

add_library(AzureStorage STATIC IMPORTED GLOBAL)
set_target_properties(AzureStorage PROPERTIES IMPORTED_LOCATION ${AZURESTORAGE_LIBRARIES})
set_target_properties(AzureStorage PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${AZURESTORAGE_INCLUDE_DIRS})
set_target_properties(AzureStorage PROPERTIES INTERFACE_LINK_LIBRARIES cpprestsdk::cpprest)
zachhilman commented 4 years ago

Hi! Thanks for the help. I ended up using a file like this (there were other deps i needed to include):

find_path(AZURESTORAGE_INCLUDE_DIRS was/blob.h REQUIRED)
find_library(AZURESTORAGE_LIBRARIES azurestorage REQUIRED)

find_package(cpprestsdk CONFIG REQUIRED)

add_library(AzureStorage STATIC IMPORTED GLOBAL)
set_target_properties(AzureStorage PROPERTIES IMPORTED_LOCATION ${AZURESTORAGE_LIBRARIES})
target_include_directories(AzureStorage INTERFACE ${AZURESTORAGE_INCLUDE_DIRS})

if (UNIX)
    list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
    find_package(OpenSSL 1.0.0 REQUIRED)
    find_package(UUID REQUIRED)
    find_package(LibXml2 REQUIRED)
    find_package(Boost REQUIRED COMPONENTS log log_setup random system thread locale regex filesystem chrono date_time)
    find_package(Threads REQUIRED)
    target_link_libraries(AzureStorage INTERFACE ${Boost_LIBRARIES} ${Boost_FRAMEWORK} ${OPENSSL_LIBRARIES} ${UUID_LIBRARIES} ${LIBXML2_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
endif ()

target_link_libraries(AzureStorage INTERFACE cpprestsdk::cpprest cpprestsdk::cpprestsdk_zlib_internal cpprestsdk::cpprestsdk_boost_internal cpprestsdk::cpprestsdk_openssl_internal)

I'm posting this here for others who have a similar situation. This has only been tested on linux.