0

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)

Code Include

Error Message

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
            }
        }
    ]
}
tommy61157
  • 164
  • 2
  • 13
  • 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 06 '18 at 12:07
  • 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 06 '18 at 12:20
  • 1
    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 06 '18 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 06 '18 at 12:25
  • copy and paste the file is much better than a screenshot – Alan Birtles Aug 06 '18 at 12:27
  • Okay, let me do that then – tommy61157 Aug 06 '18 at 12:27
  • You need to add your include path to your gcc command line, e.g. `-I /home/....` – Alan Birtles Aug 06 '18 at 12:34
  • So, including the src folder with the source files or just the whole directory that's loaded into Visual studio code itself? Do I have to include the opencv include folder and the json include folder? If so, How do I list multiple includes properly in a single argument or do I have to do -I multiple times if I'm including more than one directory in the g++ compiler? – tommy61157 Aug 06 '18 at 12:44
  • 1
    A separate argument for each directory – Alan Birtles Aug 06 '18 at 12:46

1 Answers1

2

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.

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
  • 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 06 '18 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 06 '18 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 06 '18 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 06 '18 at 13:00
  • Is "json.hpp" in the "/home/linuxbrew/.linuxbrew/Cellar/nlohmann_json/3.1.2/include/nlohmann" directory? – Alan Birtles Aug 06 '18 at 13:04
  • Yes, it is included in that directory, that's actually the only file in that directory. (which according to nlohmann is how it's supposed to be) – tommy61157 Aug 06 '18 at 13:06
  • 1
    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 06 '18 at 13:11
  • The file wasn't saved, that was the issue, forgot about that, put in a quick edit to say to make sure to save changes to tasks.json, and I'll mark your answer as correct. I'm having another issue with the code now, but it's unrelated to this and has more to do with the program itself, so I'm going to post it as a separate question. – tommy61157 Aug 06 '18 at 13:20