Trouble setting up c++ with VSCode. Include error, missing binary operator and xlocale.h not found

62 views Asked by At

I'm trying to test the following C++ code on VSCode, but can't seem to get it to work. So far online searches haven't provided results. Tried to change the compilers but it doesn't seem to fix itself. Not sure how I proceed further. OS is ubuntu if relevant:

#include <iostream> //input output library, containing printing and asking input etc.

int main() {
    std::cout << "test"; //statement
    return 0; //tells system it terminated correctly
}

The following errors are mentioned under the problems window:

test.cpp

#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (/mnt/F894C3B494C373A2/Downloads/c++/test.cpp).

cannot open source file "xlocale.h" (dependency of "iostream")

studio.h /usr/include

missing binary operator before token "(" .. a few times

libc-header-start.h /usr/include/x86_64-linux-gnu/bits

missing binary operator before token "("

cdefs.h /usr/include/x86_64-linux-gnu/sys

missing binary operator before token "("

The terminal window has this output:

 *  Executing task: C/C++: gcc build active file 

Starting build...
/home/mike/mesasdk/bin/gcc -fdiagnostics-color=always -g /mnt/F894C3B494C373A2/Downloads/c++/test.cpp -o /mnt/F894C3B494C373A2/Downloads/c++/test
In file included from /home/mike/mesasdk/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include-fixed/features.h:338,
                 from /home/mike/mesasdk/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/os_defines.h:39,
                 from /home/mike/mesasdk/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/c++config.h:655,
                 from /home/mike/mesasdk/include/c++/12.1.0/iostream:38,
                 from /mnt/F894C3B494C373A2/Downloads/c++/test.cpp:1:
/usr/include/x86_64-linux-gnu/sys/cdefs.h:492:49: error: missing binary operator before token "("
  492 | #if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5)
      |                                                 ^
In file included from /usr/include/stdio.h:27,
                 from /home/mike/mesasdk/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include-fixed/wchar.h:46,
                 from /home/mike/mesasdk/include/c++/12.1.0/cwchar:44,
                 from /home/mike/mesasdk/include/c++/12.1.0/bits/postypes.h:40,
                 from /home/mike/mesasdk/include/c++/12.1.0/iosfwd:40,
                 from /home/mike/mesasdk/include/c++/12.1.0/ios:38,
                 from /home/mike/mesasdk/include/c++/12.1.0/ostream:38,
                 from /home/mike/mesasdk/include/c++/12.1.0/iostream:39:
/usr/include/x86_64-linux-gnu/bits/libc-header-start.h:56:17: error: missing binary operator before token "("
   56 | #if __GLIBC_USE (IEC_60559_BFP_EXT) || __GLIBC_USE (ISOC2X)
      |                 ^
/usr/include/x86_64-linux-gnu/bits/libc-header-start.h:73:17: error: missing binary operator before token "("
   73 | #if __GLIBC_USE (IEC_60559_FUNCS_EXT) || __GLIBC_USE (ISOC2X)
      |                 ^
/usr/include/stdio.h:290:43: error: missing binary operator before token "("
  290 | #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
      |                                           ^
/usr/include/stdio.h:363:17: error: missing binary operator before token "("
  363 | #if __GLIBC_USE (LIB_EXT2)
      |                 ^
/usr/include/stdio.h:405:18: error: missing binary operator before token "("
  405 | #if !__GLIBC_USE (DEPRECATED_SCANF) && !defined __LDBL_COMPAT
      |                  ^
/usr/include/stdio.h:449:19: error: missing binary operator before token "("
  449 | # if !__GLIBC_USE (DEPRECATED_SCANF)
      |                   ^
/usr/include/stdio.h:567:17: error: missing binary operator before token "("
  567 | #if __GLIBC_USE (DEPRECATED_GETS)
      |                 ^
/usr/include/stdio.h:592:43: error: missing binary operator before token "("
  592 | #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
      |                                           ^
/home/mike/mesasdk/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include-fixed/wchar.h:175:11: fatal error: xlocale.h: No such file or directory
  175 | # include <xlocale.h>
      |           ^~~~~~~~~~~
compilation terminated.

Build finished with error(s).

 *  The terminal process failed to launch (exit code: -1). 
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: C/C++: gcc build active file 

Starting build...
/home/mike/mesasdk/bin/gcc -fdiagnostics-color=always -g /mnt/F894C3B494C373A2/Downloads/c++/test.cpp -o /mnt/F894C3B494C373A2/Downloads/c++/test
In file included from /home/mike/mesasdk/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include-fixed/features.h:338,
                 from /home/mike/mesasdk/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/os_defines.h:39,
                 from /home/mike/mesasdk/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/c++config.h:655,
                 from /home/mike/mesasdk/include/c++/12.1.0/iostream:38,
                 from /mnt/F894C3B494C373A2/Downloads/c++/test.cpp:1:
/usr/include/x86_64-linux-gnu/sys/cdefs.h:492:49: error: missing binary operator before token "("
  492 | #if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5)
      |                                                 ^
In file included from /usr/include/stdio.h:27,
                 from /home/mike/mesasdk/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include-fixed/wchar.h:46,
                 from /home/mike/mesasdk/include/c++/12.1.0/cwchar:44,
                 from /home/mike/mesasdk/include/c++/12.1.0/bits/postypes.h:40,
                 from /home/mike/mesasdk/include/c++/12.1.0/iosfwd:40,
                 from /home/mike/mesasdk/include/c++/12.1.0/ios:38,
                 from /home/mike/mesasdk/include/c++/12.1.0/ostream:38,
                 from /home/mike/mesasdk/include/c++/12.1.0/iostream:39:
/usr/include/x86_64-linux-gnu/bits/libc-header-start.h:56:17: error: missing binary operator before token "("
   56 | #if __GLIBC_USE (IEC_60559_BFP_EXT) || __GLIBC_USE (ISOC2X)
      |                 ^
/usr/include/x86_64-linux-gnu/bits/libc-header-start.h:73:17: error: missing binary operator before token "("
   73 | #if __GLIBC_USE (IEC_60559_FUNCS_EXT) || __GLIBC_USE (ISOC2X)
      |                 ^
/usr/include/stdio.h:290:43: error: missing binary operator before token "("
  290 | #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
      |                                           ^
/usr/include/stdio.h:363:17: error: missing binary operator before token "("
  363 | #if __GLIBC_USE (LIB_EXT2)
      |                 ^
/usr/include/stdio.h:405:18: error: missing binary operator before token "("
  405 | #if !__GLIBC_USE (DEPRECATED_SCANF) && !defined __LDBL_COMPAT
      |                  ^
/usr/include/stdio.h:449:19: error: missing binary operator before token "("
  449 | # if !__GLIBC_USE (DEPRECATED_SCANF)
      |                   ^
/usr/include/stdio.h:567:17: error: missing binary operator before token "("
  567 | #if __GLIBC_USE (DEPRECATED_GETS)
      |                 ^
/usr/include/stdio.h:592:43: error: missing binary operator before token "("
  592 | #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
      |                                           ^
/home/mike/mesasdk/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include-fixed/wchar.h:175:11: fatal error: xlocale.h: No such file or directory
  175 | # include <xlocale.h>
      |           ^~~~~~~~~~~
compilation terminated.

Build finished with error(s).

 *  The terminal process failed to launch (exit code: -1). 
 *  Terminal will be reused by tasks, press any key to close it. 

The tasks.json file:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc build active file",
            "command": "/home/mike/mesasdk/bin/gcc",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        },
        {
            "type": "cppbuild",
            "label": "C/C++: gcc-9 build active file",
            "command": "/usr/bin/gcc-9",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "Task generated by Debugger."
        },
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/home/mike/mesasdk/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

The launch.json file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C/C++: gcc-9 build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: gcc-9 build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        },
        {
            "name": "C/C++: g++ build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++ build active file",
            "miDebuggerPath": "/home/mike/mesasdk/bin/gdb"
        }
    ]
}

The c_cpp_properties.json file:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "cStandard": "c17",
            "cppStandard": "gnu++17",
            "intelliSenseMode": "linux-gcc-x64",
            "compilerPath": "/home/mike/mesasdk/bin/gcc"
        }
    ],
    "version": 4
}

Changed compilers, reinstalled a few of them and tried to update compilers to a later version (were already latest).

EDIT:

Trying to run the test program through terminal gives same error:

c++ test.cpp 
In file included from /home/mike/mesasdk/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include-fixed/features.h:338,
                 from /home/mike/mesasdk/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/os_defines.h:39,
                 from /home/mike/mesasdk/include/c++/12.1.0/x86_64-pc-linux-gnu/bits/c++config.h:655,
                 from /home/mike/mesasdk/include/c++/12.1.0/iostream:38,
                 from test.cpp:1:
/usr/include/x86_64-linux-gnu/sys/cdefs.h:492:49: error: missing binary operator before token "("
  492 | #if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5)
      |                                                 ^
In file included from /usr/include/stdio.h:27,
                 from /home/mike/mesasdk/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include-fixed/wchar.h:46,
                 from /home/mike/mesasdk/include/c++/12.1.0/cwchar:44,
                 from /home/mike/mesasdk/include/c++/12.1.0/bits/postypes.h:40,
                 from /home/mike/mesasdk/include/c++/12.1.0/iosfwd:40,
                 from /home/mike/mesasdk/include/c++/12.1.0/ios:38,
                 from /home/mike/mesasdk/include/c++/12.1.0/ostream:38,
                 from /home/mike/mesasdk/include/c++/12.1.0/iostream:39:
/usr/include/x86_64-linux-gnu/bits/libc-header-start.h:56:17: error: missing binary operator before token "("
   56 | #if __GLIBC_USE (IEC_60559_BFP_EXT) || __GLIBC_USE (ISOC2X)
      |                 ^
/usr/include/x86_64-linux-gnu/bits/libc-header-start.h:73:17: error: missing binary operator before token "("
   73 | #if __GLIBC_USE (IEC_60559_FUNCS_EXT) || __GLIBC_USE (ISOC2X)
      |                 ^
/usr/include/stdio.h:290:43: error: missing binary operator before token "("
  290 | #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
      |                                           ^
/usr/include/stdio.h:363:17: error: missing binary operator before token "("
  363 | #if __GLIBC_USE (LIB_EXT2)
      |                 ^
/usr/include/stdio.h:405:18: error: missing binary operator before token "("
  405 | #if !__GLIBC_USE (DEPRECATED_SCANF) && !defined __LDBL_COMPAT
      |                  ^
/usr/include/stdio.h:449:19: error: missing binary operator before token "("
  449 | # if !__GLIBC_USE (DEPRECATED_SCANF)
      |                   ^
/usr/include/stdio.h:567:17: error: missing binary operator before token "("
  567 | #if __GLIBC_USE (DEPRECATED_GETS)
      |                 ^
/usr/include/stdio.h:592:43: error: missing binary operator before token "("
  592 | #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
      |                                           ^
/home/mike/mesasdk/lib/gcc/x86_64-pc-linux-gnu/12.1.0/include-fixed/wchar.h:175:11: fatal error: xlocale.h: No such file or directory
  175 | # include <xlocale.h>
      |           ^~~~~~~~~~~
compilation terminated.
mike@mike-Legion-Y540-15IRH:/mnt/F894C3B494C373A2/Downloads/c++$ update-alternatives --query gcc
update-alternatives: error: no alternatives for gcc
mike@mike-Legion-Y540-15IRH:/mnt/F894C3B494C373A2/Downloads/c++$ update-alternatives --query g++
update-alternatives: error: no alternatives for g++

1

There are 1 answers

0
Mike On

The problem, after some hours, lay in the fixed header lines of the mesa sdk apparently. Using

GCC_VERSION=`gcc --version | grep ^gcc | sed 's/^.* //g'`
$MESASDK_ROOT/libexec/gcc/x86_64-pc-linux-gnu/$GCC_VERSION/install-tools/mkheaders $MESASDK_ROOT

solved it.