beached / daw_json_link

Fast, convenient JSON serialization and parsing in C++
https://beached.github.io/daw_json_link/
Boost Software License 1.0
474 stars 31 forks source link

Error linking daw_json_link with MSVC #381

Closed Beafantles closed 1 year ago

Beafantles commented 1 year ago

Hello, I've tried to use daw-json-link library on my Windows laptop but it reaches an error that I don't face on Linux. I've setup a basic example to reproduce the bug:

main.cpp:

// main.cpp
#include <daw/json/daw_json_link.h>

int main()
{
    return 0;
}

CMakeLists.txt:

# CMakeLists.txt
cmake_minimum_required(VERSION 3.12)

project(daw-json-test)

find_package(daw-json-link CONFIG REQUIRED)

add_executable(test ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
target_link_libraries(test PRIVATE daw::daw-json-link)

When I try to build this basic project after installing daw-json-library through vcpkg, I get an error. Here's the complete console output:

PS C:\Users\USER\Documents\tmp\daw-json-test> mkdir build

    Directory: C:\Users\USER\Documents\tmp\daw-json-test

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----           5/11/2023  4:57 PM                build

PS C:\Users\USER\Documents\tmp\daw-json-test> cd .\build\
PS C:\Users\USER\Documents\tmp\daw-json-test\build> cmake -DCMAKE_TOOLCHAIN_FILE=C:/Users/USER/src/vcpkg/scripts/buildsystems/vcpkg.cmake ..  
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22621.
-- The C compiler identification is MSVC 19.35.32217.1
-- The CXX compiler identification is MSVC 19.35.32217.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (12.7s)
-- Generating done (0.3s)
-- Build files have been written to: C:/Users/USER/Documents/tmp/daw-json-test/build
PS C:\Users\USER\Documents\tmp\daw-json-test\build> cmake --build .    
MSBuild version 17.5.1+f6fdcf537 for .NET Framework

  Checking Build System
  Building Custom Rule C:/Users/USER/Documents/tmp/daw-json-test/CMake
  Lists.txt
  main.cpp
C:\Users\USER\src\vcpkg\installed\x64-windows\include\daw\json\impl\..
/daw_json_switches.h(154,30): fatal  error C1012: unmatched parenthesis 
: missing ')' [C:\Users\USER\Documents\tmp\daw-json-test\build\test.vc 
xproj]

My laptop is running on Windows 11, with latest Visual Studio 2022 version (17.5.5), vcpkg up-to-date, and CMake v3.26.3.

beached commented 1 year ago

This is odd, that line is

#if( defined( DAW_HAS_MSVC ) and __cpp_constexpr > 201700L )

and that file is always included.

There's no more to the error about what parenthesis is missing it's match, is there?

Beafantles commented 1 year ago

No, there's not, that's all the output I got from the console :( I don't know if that matters but I used v3.15.0 (apparently, it is not yet possible to update it to 3.16.0 from vcpkg).

beached commented 1 year ago

Got this setup and into MSVC. This looks like an MSVC issue and /permissive- as a compile option fixes it.

beached commented 1 year ago

did some further investigating. You can also set -DCMAKE_CXX_STANDARD=20 as /permissive- is the default for MSVC 2022 in C++20 mode too. Otherwise it looks like for cmake projects, it does not add /permissive- like the default for new MSVC projects via gui

beached commented 1 year ago

going to close this, but if you think it should be a bug let me know. It is a std conformity issue with MSVC though

beached commented 1 year ago

There is a fix in the latest github that will allow for not having /permissive- too. Will be in the next vcpkg release

Beafantles commented 1 year ago

Nice, thank you very much :D Have a great day!