Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile error #60

Open
hyq5436 opened this issue Mar 8, 2022 · 8 comments
Open

compile error #60

hyq5436 opened this issue Mar 8, 2022 · 8 comments

Comments

@hyq5436
Copy link

hyq5436 commented Mar 8, 2022

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

#ifdef __cpp_lib_span
#include <span>
#else
#include <gsl/span>
#endif
@mariusbancila
Copy link
Owner

#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 ()

@slav-slavov-schneider
Copy link

slav-slavov-schneider commented May 9, 2022

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'

@mariusbancila
Copy link
Owner

How are you building? Is UUID_USING_CXX20_SPAN set to ON or is it OFF?

@slav-slavov-schneider
Copy link

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)

@slav-slavov-schneider
Copy link

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);
}

@slav-slavov-schneider
Copy link

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)

@mariusbancila
Copy link
Owner

Does this solution is suitable for you?

@slav-slavov-schneider
Copy link

Yes, I am OK with the fetch method. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants