VS Code G++ intellisense settings not working and compiler not running to completion

Viewed 130

So I'm trying to use vs code as my ide on linux for the GNU c/c++ toolset.

Thus far not with a great amount of success.

The first part is intellisense.

I am using the Microsoft c/c++ extension for this. I followed what common sense told me and then I also followed what the extenstion told me to do which ended up being the same thing.

See below. Even after reloading the window intellisense is not working.

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/Data/Documents/CensusProject/gdallib/src/compiled/include/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu17",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

The next part is building.

To build from the commandline I have to do the following:

PKG_CONFIG_PATH=/Data/Documents/CensusProject/gdallib/src/compiled/lib/pkgconfig
LIBRARY_PATH=/Data/Documents/CensusProject/gdallib/src/compiled/lib
LD_LIBRARY_PATH=/Data/Documents/CensusProject/gdallib/src/compiled/lib/
C_INCLUDE_PATH=/Data/Documents/CensusProject/gdallib/src/compiled/include/
CPLUS_INCLUDE_PATH=/Data/Documents/CensusProject/gdallib/src/compiled/include/
export  PKG_CONFIG_PATH
export LIBRARY_PATH
export LD_LIBRARY_PATH
export C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH

So I placed these in tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}",
                "env":{ 
                    "PKG_CONFIG_PATH":"/Data/Documents/CensusProject/gdallib/src/compiled/lib/pkgconfig",
                    "LIBRARY_PATH":"/Data/Documents/CensusProject/gdallib/src/compiled/lib",
                    "LD_LIBRARY_PATH":"/Data/Documents/CensusProject/gdallib/src/compiled/lib/",
                    "C_INCLUDE_PATH":"/Data/Documents/CensusProject/gdallib/src/compiled/include/",
                    "CPLUS_INCLUDE_PATH":"/Data/Documents/CensusProject/gdallib/src/compiled/include/"
            }
                
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "compiler: /usr/bin/g++"
        }
    ]
}

Running the task lead to Starting build... /usr/bin/g++ -g /Data/Documents/CensusProject/gdallib/src/compiled/GdalTest/test.cpp -o /Data/Documents/CensusProject/gdallib/src/compiled/GdalTest/test collect2: fatal error: cannot find 'ld' compilation terminated. Build finished with error(s). The terminal process terminated with exit code: -1.

which is a bit of an improvement, as before the compiler errored about not finding the header files etc... its sort of an improvement.

in the shell this works fine.

Is anyone else familiar with these problems ? Thanks in advance.

1 Answers

In your case, the directory where the "ld" program was located had not been defined in the PATH environment variable. Firstly you should add it. Example:-

export PATH=$PATH:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin

Related