Vcpkg: Boost-uuid should link against bcrypt on windows

Created on 16 Oct 2018  路  4Comments  路  Source: microsoft/vcpkg

Most helpful comment

Sure.
Let me first explain my rationale. If you look at https://github.com/boostorg/uuid/blob/develop/include/boost/uuid/detail/random_provider_bcrypt.ipp#L20, you'll find:

#if defined(BOOST_UUID_FORCE_AUTO_LINK) || (!defined(BOOST_ALL_NO_LIB) && !defined(BOOST_UUID_RANDOM_PROVIDER_NO_LIB))
#   define BOOST_LIB_NAME "bcrypt"
#   if defined(BOOST_AUTO_LINK_NOMANGLE)
#      include <boost/config/auto_link.hpp>
#   else
#      define BOOST_AUTO_LINK_NOMANGLE
#      include <boost/config/auto_link.hpp>
#      undef BOOST_AUTO_LINK_NOMANGLE
#   endif

which defines the condition under which boost will link against the bcrypt library. Since BOOST_ALL_NO_LIB is set by vcpkg, I just need to set BOOST_UUID_FORCE_AUTO_LINK. There are multiple ways to do that. I am using CMake, so I set the compiler flag to define this variable. My CMakeLists.txt contains:

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_WIN32_WINNT=0x0601 -DBOOST_UUID_FORCE_AUTO_LINK")
  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D_WIN32_WINNT=0x0601 -DBOOST_UUID_FORCE_AUTO_LINK")

If you're using CMake, you can add -DBOOST_UUID_FORCE_AUTO_LINK to your options.

There is another way to do this, which I was using before:
I link my executable against both boost libraries and bcrypt. So something like:

find_package(Boost REQUIRED COMPONENTS system serialization)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(my_lib ${Boost_SYSTEM_LIBRARY} 
    ${Boost_SERIALIZATION_LIBRARY} bcrypt...)

This worked but the problem was that windows complains about having to search the bcrypt library which shows up as a warning when you run cmake.

All 4 comments

Hi I am running into this issue trying to build ome-files as a dll on Windows using a vcpkg environment. Is there a workaround for this?

FYI, they have the following definition in CMakeLists.txt

add_definitions(-DBOOST_ALL_DYN_LINK -DBOOST_ALL_NO_LIB)

I had the same issue with vcpkg messing up boost's linking.
I fixed it by defining BOOST_UUID_FORCE_AUTO_LINK by using the compiler options.

Hi sagarjha, could you explain how you did that? I saw the suggestion to do so, but no explanation of how.

Sure.
Let me first explain my rationale. If you look at https://github.com/boostorg/uuid/blob/develop/include/boost/uuid/detail/random_provider_bcrypt.ipp#L20, you'll find:

#if defined(BOOST_UUID_FORCE_AUTO_LINK) || (!defined(BOOST_ALL_NO_LIB) && !defined(BOOST_UUID_RANDOM_PROVIDER_NO_LIB))
#   define BOOST_LIB_NAME "bcrypt"
#   if defined(BOOST_AUTO_LINK_NOMANGLE)
#      include <boost/config/auto_link.hpp>
#   else
#      define BOOST_AUTO_LINK_NOMANGLE
#      include <boost/config/auto_link.hpp>
#      undef BOOST_AUTO_LINK_NOMANGLE
#   endif

which defines the condition under which boost will link against the bcrypt library. Since BOOST_ALL_NO_LIB is set by vcpkg, I just need to set BOOST_UUID_FORCE_AUTO_LINK. There are multiple ways to do that. I am using CMake, so I set the compiler flag to define this variable. My CMakeLists.txt contains:

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_WIN32_WINNT=0x0601 -DBOOST_UUID_FORCE_AUTO_LINK")
  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -D_WIN32_WINNT=0x0601 -DBOOST_UUID_FORCE_AUTO_LINK")

If you're using CMake, you can add -DBOOST_UUID_FORCE_AUTO_LINK to your options.

There is another way to do this, which I was using before:
I link my executable against both boost libraries and bcrypt. So something like:

find_package(Boost REQUIRED COMPONENTS system serialization)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(my_lib ${Boost_SYSTEM_LIBRARY} 
    ${Boost_SERIALIZATION_LIBRARY} bcrypt...)

This worked but the problem was that windows complains about having to search the bcrypt library which shows up as a warning when you run cmake.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

grandprixgp picture grandprixgp  路  3Comments

angelmixu picture angelmixu  路  3Comments

cjvaijo picture cjvaijo  路  3Comments

aspioupiou picture aspioupiou  路  3Comments

cskrisz picture cskrisz  路  3Comments