c++visual-studio-codeeigeninclude-path

C++, Eigen library, #include does not see the file/directory


My #include <Eigen/Dense> gives the error: No such file or directory. I followed tutorials on how to include it, my outcome appears to be different.

My tasks.json is:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\msys64\\ucrt64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-I C:\\Users\\press\\projects\\helloworld\\eigen-3.4.0\\"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

My c_cpp_properties.json is:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\Users\\press\\projects\\helloworld\\eigen-3.4.0\\"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\msys64\\ucrt64\\bin\\gcc.exe",
            "cStandard": "c17",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}

My actual directory path is correct as far as I can tell, I attached a screenshot.Directory screenshot

How do I make the Eigen library work?

Notes: I have looked for answers on forums but it didn't help. I use Windows. I use VS code.

Edits: If my question isn't satisfactory for any reason, I'd be very greatful for tips on how to improve it. I genuinely put effort into this and tried to make it as concise as possible.


Solution

  • In tasks.json

    "-I C:\\Users\\press\\projects\\helloworld\\eigen-3.4.0\\"
    

    should be either

    "-IC:\\Users\\press\\projects\\helloworld\\eigen-3.4.0\\"
    

    or

    "-I",
    "C:\\Users\\press\\projects\\helloworld\\eigen-3.4.0\\"
    

    Each element of args should be a single argument. Spaces separate arguments so they shouldn't be placed within an argument. If you do that (as you did) then VSCode will escape the space so it no longer operates to separate two arguments. Instead you get a single argument with an embedded space.

    The compiler you are using will accept either one argument -Ipath or two arguments -I path but what you wrote didn't correspond to either of those possibilities.