jorgen / json_struct

json_struct is a single header only C++ library for parsing JSON directly to C++ structs and vice versa
Other
422 stars 57 forks source link

How to Install this? #2

Closed Bobisback closed 5 years ago

Bobisback commented 5 years ago

Hello, I am trying to use this in a C++ dll project I have. I am just not sure how to install this?

seems like I just copy the json_tools.h into my project, but this is causing the following error on line 4088: C2589 '(': illegal token on right side of '::'

Which makes no since considering the code does not have that at all. What am I missing?

Thanks, Bob

jorgen commented 5 years ago

Hey, Yes the idea is that you just copy the header to a suitable place and include it in the source.

I would love to help you out, but I need a bit more since I’m not certain what the problem is. Are you using visual studio 2013 or above? Could you send me a small example of your code?

Bobisback commented 5 years ago

I am using Visual Studio 2017, latest version with a brand new C++ dll project. I do not have any sample code right this second. If I get some time tomorrow I may be able to do a sample project.

I really wanted to use this but could not figure it out so just parsing the stuff manually right now.

jorgen commented 5 years ago

This is odd. Travis CI run the auto test for every build and they are succeeding right now. I will try and figure out what’s going wrong if you give a sample project. Could we start with the full error log?

Bobisback commented 5 years ago

What it actually sounds like to me is a hidden character bug. It used to happen to me all the time in C especially when switching between platforms (aka mac to windows). Basically there is some special ASCII char hidden in the file somewhere, on some computers it just ignores it and on others it does not.

What is interesting is if I comment out the line that it errors on many other errors show up. What is also interesting is visual studio does not show an error unless I compile it. This again suggests the above, meaning the compiler sinces this char but visual studio does not. Also intellisence works fine and also shows no issues.

With this in mind I tried copying the file directly from the zip and also copying the raw text from github into a new file. Both with the same result. The error above is the full log when I compile in Visual Studio. Not sure if there is a way to get a more verbose output or not.

Bobisback commented 5 years ago

json_tools_error

Here is a screen capture of the issue. So steps to reproduce for me are add the header file to the project. Import it and use it. Then build the project. Here is my visual studio info.

What is crazy is the chars are perfectly correct hahaa and what it says is just not right. That is why I just assumed I installed it incorrectly. In fact I am not really sure I still have it installed correctly. i am very new to c++ so.


Version 15.9.11
VisualStudio.15.Release/15.9.11+28307.586
Microsoft .NET Framework
Version 4.7.03056

Installed Version: Community

Visual C++ 2017   00369-60000-00001-AA171
Microsoft Visual C++ 2017

Application Insights Tools for Visual Studio Package   8.14.20131.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017   15.9.04012.0
ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services   15.8.31590
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2017   5.2.61435.0
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   15.9.03024.0
Azure App Service Tools v3.0.0

Azure Data Lake Node   1.0
This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio   2.3.3000.2
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   15.9.03024.0
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.3.3000.2
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.1.49 (remotes/origin/d15-8@ee674f3)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Fabric.DiagnosticEvents   1.0
Fabric Diagnostic Events

GhostDoc   19.1.19100.0
Generate XML Comments from your code, maintain clean and up-to-date documentation, produce help documentation in multiple formats, use intelligent source code Spell Checker in Visual Studio.

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

JavaScript UWP Project System   2.0
JavaScript UWP Project System

JetBrains ReSharper Ultimate 2017.3.2    Build 111.0.20180201.63358
JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2019 JetBrains, Inc.

Microsoft Azure HDInsight Azure Node   2.3.3000.2
HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service   2.3.3000.2
Language service for Hive query

Microsoft Azure Service Fabric Tools for Visual Studio   2.4
Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service   2.3.3000.2
Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node   1.0
Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.0.0

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   1.0
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

MLGen Package Extension   1.0
MLGen Package Visual Studio Extension Detailed Info

Mono Debugging for Visual Studio   4.13.12-pre (9bc9548)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   4.6.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Office Developer Tools for Visual Studio 2017 ENU   15.0.28224.00
Microsoft Office Developer Tools for Visual Studio 2017 ENU

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension   1.0
ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension   1.0
ResourcePackage Visual Studio Extension Detailed Info

SQL Server Data Tools   15.1.61903.01040
Microsoft SQL Server Data Tools

Test Adapter for Boost.Test   1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test.  The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test   1.0
Enables Visual Studio's testing tools with unit tests written for Google Test.  The use terms and Third Party Notices are available in the extension installation directory.

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   15.9.20918.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.2 for F# 4.5   15.8.0.0.  Commit Hash: 6e26c5bacc8c4201e962f5bdde0a177f82f88691.
Microsoft Visual F# Tools 10.2 for F# 4.5

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for CMake   1.0
Visual Studio Tools for CMake

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

Visual Studio Tools for Unity   3.9.0.3
Visual Studio Tools for Unity

Visual Studio Tools for Universal Windows Apps   15.0.28307.556
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   4.12.3.83 (d15-9@23fa80172)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   4.16.30 (e0af99a34)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   1.1.128 (6f5ebb2)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   9.1.7.0 (HEAD/ba9da7a76)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK   12.4.0.64 (9c8d8e0)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.```
jorgen commented 5 years ago

Ah! I know what this is :( it’s the min max thing in windows.h :( I only undef min in json_tools.h.

On the line above where you include json_tools.h do: #undef max. This is a workaround obviously:) hope it works🤞

jorgen commented 5 years ago

Please let me know if it solves it for you. I will fix it tomorrow if this is the case.

Bobisback commented 5 years ago

Ya that seemed to fix it. It is compiling now.

Thanks!

jorgen commented 5 years ago

Ok, I have added a #error directive to json_tools.h making the build fail with a sensible compiler error if either max or min macros are defined (ie. #define NOMINMAX 1 on windows before including Windows.h). I have also added a note to the Readme.md about json_tool.h being the only header needed and that it should be copied into the projects include path.

Bobisback commented 5 years ago

Fantastic thanks a ton for the help!!

Bobisback commented 5 years ago

Ok so with the new version now I really do not understand how to install it. hahaa Now I am getting errors, so I need to remove the error line you put in and add the include. But now the min functions on line 1512, 1513, and 1798 are erroring with "expecting identifier" errors.

jorgen commented 5 years ago

But are you not getting an error message saying you should define the NOMINMAX define. Just place that define as a compiler option and it should work. Alternatively you can undef min and max before including json_tools.h? The reason I solved it that way is bacause I think it is a bit evil to undefine macros inside and the header, so instead I’m telling the user to do it correctly before including windows.h

Hope you get it to work!