nlohmann JSON C++ Include issue
Clash Royale CLAN TAG#URR8PPP
nlohmann JSON C++ Include issue
I'm currently having an issue to where visual studio code is not recognizing the include of the json.hpp file no matter what I do in the IDE, I don't admittedly know if the issue is being caused by the IDE, my own silly mistake, or by the way the json library is installed. I used linuxbrew on Ubuntu Server 16.04 LTS in order to install it, and I have the latest stable version. I'm using the g++ compiler (version 5.5 I believe)
I'm still new to this, so I included screenshots of the error it brings up along with how it is mentioned in the code in order to hopefully provide some insight as to what is going on. Feel free to ask if more information is needed.
c_cpp_properties.json:
"configurations": [
"name": "Linux",
"includePath": [
"$workspaceFolder/**",
"opt/opencv/release/include",
"/home/linuxbrew/.linuxbrew/Cellar/nlohmann_json/3.1.2/include"
],
"defines": ,
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
],
"version": 4
tasks.json:
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
"label": "build app",
"type": "shell",
"command": "g++",
"args": [
"-g", "src/calibration.cpp",
"-o", "build/calibration.out",
"-std=c++11",
"-L/usr/local/Cellar/opencv/3.4.1_5/lib",
"-lopencv_stitching",
"-lopencv_superres",
"-lopencv_videostab",
"-lopencv_aruco",
"-lopencv_bgsegm",
"-lopencv_bioinspired",
"-lopencv_ccalib",
"-lopencv_dnn_objdetect",
"-lopencv_dpm",
"-lopencv_face",
"-lopencv_photo",
"-lopencv_fuzzy",
"-lopencv_hfs",
"-lopencv_img_hash",
"-lopencv_line_descriptor",
"-lopencv_optflow",
"-lopencv_reg",
"-lopencv_rgbd",
"-lopencv_saliency",
"-lopencv_stereo",
"-lopencv_structured_light",
"-lopencv_phase_unwrapping",
"-lopencv_surface_matching",
"-lopencv_tracking",
"-lopencv_datasets",
"-lopencv_dnn",
"-lopencv_plot",
"-lopencv_xfeatures2d",
"-lopencv_shape",
"-lopencv_video",
"-lopencv_ml",
"-lopencv_ximgproc",
"-lopencv_calib3d",
"-lopencv_features2d",
"-lopencv_highgui",
"-lopencv_videoio",
"-lopencv_flann",
"-lopencv_xobjdetect",
"-lopencv_imgcodecs",
"-lopencv_objdetect",
"-lopencv_xphoto",
"-lopencv_imgproc",
"-lopencv_core"
],
"group":
"kind": "build",
"isDefault": true
]
I use Ctrl+Shift+b in visual studio code to build the code, if you can offer the g++ command to build it with g++ outside of visual studio code, I could test that. The Calibration.cpp, calibration.h, and possibly the camera.json are the only files involved in the program other than potentially the .vscode files.
– tommy61157
Aug 6 at 12:20
Yes, but in order for "ctrl shift b" to work in vs code you must have created a build task in "tasks.json"
– Alan Birtles
Aug 6 at 12:22
Right, sorry, wasn't fully aware of what you meant, I'll edit the main post to have the images of the code, sorry, due to the odd setup I have, it's actually best if I just do that for now.
– tommy61157
Aug 6 at 12:25
A separate argument for each directory
– Alan Birtles
Aug 6 at 12:46
1 Answer
1
You need to add the include path to your gcc command line, for example:
....
"args": [
"-g", "src/calibration.cpp",
"-o", "build/calibration.out",
"-std=c++11",
"-I/home/linuxbrew/.linuxbrew/Cellar/nlohmann_json/3.1.2/include",
....
Make sure to save the file before building.
I included it just like you showed (my directory is very slightly different, so I did correct for that along with being sure to add a space between the -I and /home/...) and I'm still getting the exact same error.
– tommy61157
Aug 6 at 12:48
you need to not have a space between "-I" and "/home", I'd have put the exact path in correctly if you'd posted the contents of your c_cpp_properties.json rather than a screenshot....
– Alan Birtles
Aug 6 at 12:52
Okay, sorry, I'll remember in the future to post files over screenshots, sorry, still new to stack exchange too, still learning a lot of the quirks and little things, give me a minute and I'll have the C++ Properties listed on the question
– tommy61157
Aug 6 at 12:54
The comment got over 5 minutes old, so I couldn't edit it, but it should be in the main post now replacing the screenshot.
– tommy61157
Aug 6 at 13:00
Check your command line for typos, make sure the tasks.json has been saved, check that the command printed in the terminal is correct
– Alan Birtles
Aug 6 at 13:11
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
visual studio code doesn't have a build system, the settings in "c_cpp_properties" are only used for intellisense. How are you building your code (defined in "tasks.json")?
– Alan Birtles
Aug 6 at 12:07