Open hyq5436 opened 2 years ago
#include <span>
should be enough, if you have the folder gsl
added to the additional include directories. That's something done with CMake when UUID_USING_CXX20_SPAN
is not set (is OFF
by default):
# Using span from std
if (NOT UUID_USING_CXX20_SPAN)
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/gsl>
$<INSTALL_INTERFACE:include/gsl>)
install(DIRECTORY gsl DESTINATION include)
endif ()
I am also facing this issue. My code builds well on Linux (g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0) but fails on Windows (VisualStudio 2019). The proposed ifdef
solution works well.
C:/Projects/myProject/ThirdParty/stduuid/include/uuid.h:18:10: fatal error: span: No such file or directory
18 | #include <span>
| ^~~~~~
compilation terminated.
Update:
Our project is configured to use C++17
If I add gsl
to the target_link_libraries
section of my library I get errors like:
The contents of <span> are available only with C++20 or later.
C:\Projects\miGenieRelease2Controller\ThirdParty\stduuid\include\uuid.h(59): error C2653: 'gsl': is not a class or namespace name
C:\Projects\miGenieRelease2Controller\ThirdParty\stduuid\include\uuid.h(59): error C2061: syntax error: identifier 'span'
How are you building? Is UUID_USING_CXX20_SPAN
set to ON
or is it OFF
?
It is the default - OFF
. I am just setting UUID_BUILD_TESTS
to OFF
in the upper CMakeLists file
set(UUID_BUILD_TESTS OFF CACHE BOOL "" FORCE)
add_subdirectory(stduuid)
Here is a small snippet that reproduces the issue. stduuid
is downloaded in a folder where main.cpp is.
CMakeLists.txt
:
project(stduuid-test)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
include(FetchContent)
FetchContent_Declare(gsl
URL "https://github.com/microsoft/GSL/archive/refs/tags/v4.0.0.zip"
URL_HASH SHA384=a769a51846f3d3336c671f3bf01fa79d8987dbd3bc337ba90e82cf5e88e18366b56a8baa05aa5fb1093c3e70283fab66
)
FetchContent_MakeAvailable(gsl)
set(UUID_BUILD_TESTS OFF CACHE BOOL "" FORCE)
add_subdirectory(stduuid)
add_executable (stduuid-test main.cpp)
target_link_libraries (stduuid-test Microsoft.GSL::GSL stduuid)
main.cpp
#include <uuid.h>
#include <cassert>
int main()
{
std::random_device rd;
auto seed_data = std::array<int, std::mt19937::state_size> {};
std::generate(std::begin(seed_data), std::end(seed_data), std::ref(rd));
std::seed_seq seq(std::begin(seed_data), std::end(seed_data));
std::mt19937 generator(seq);
uuids::uuid_random_generator gen{generator};
uuids::uuid const id = gen();
assert(!id.is_nil());
assert(id.as_bytes().size() == 16);
assert(id.version() == uuids::uuid_version::random_number_based);
assert(id.variant() == uuids::uuid_variant::rfc);
}
And while trying this I decided to fetch stduuid instead of downloading into the project folder and with this change in the CMakeLists
file the issue does not appear.
project(stduuid-test)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
include(FetchContent)
FetchContent_Declare(gsl
URL "https://github.com/microsoft/GSL/archive/refs/tags/v4.0.0.zip"
URL_HASH SHA384=a769a51846f3d3336c671f3bf01fa79d8987dbd3bc337ba90e82cf5e88e18366b56a8baa05aa5fb1093c3e70283fab66
)
FetchContent_MakeAvailable(gsl)
set(UUID_BUILD_TESTS OFF CACHE BOOL "" FORCE)
FetchContent_Declare(stduuid
GIT_REPOSITORY "https://github.com/mariusbancila/stduuid.git"
)
FetchContent_MakeAvailable(stduuid)
add_executable (stduuid-test main.cpp)
target_link_libraries (stduuid-test Microsoft.GSL::GSL stduuid)
Does this solution is suitable for you?
Yes, I am OK with the fetch method. Thanks.
compile error when compile with nlohmann json.
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\filesystem(499,21): error C2039: 'find_if_not': is not a member of 'std' 1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\filesystem(40): message : see declaration of 'std' 1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\filesystem(499,32): error C3861: 'find_if_not': identifier not found 1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\filesystem(507,42): error C2039: 'find_if_not': is not a member of 'std'
and compile error gone when i modify uuid.h and header file include path to directory upper gsl
#include <span>
to