0

I recently made a couple of changes on my Mac. Intending to start working with C++ I installed cmake and modified my $PATH variable. I updated to the newest version of Ventura.

Now, spotlight search and apple mail are not working working anymore. Additionally (and more annoying), I cannot debug, and compile cpp files as before in VS-Code.

But receive the following error message:

Starting build...
/opt/homebrew/bin/g++-11 -fdiagnostics-color=always -g "/Users/jakobnitschke/Library/Mobile Documents/com\~apple\~CloudDocs/PhD/Learning_cplusplus/Jumping_into_cpp/sample_code/ch1/hello.cpp" -o "/Users/jakobnitschke/Library/Mobile Documents/com\~apple\~CloudDocs/PhD/Learning_cplusplus/Jumping_into_cpp/sample_code/ch1/hello"
/bin/sh: /opt/homebrew/bin/g++-11: No such file or directory

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.

My current $PATH:

/Users/jakobnitschke/opt/anaconda3/bin
/Users/jakobnitschke/opt/anaconda3/condabin
/opt/homebrew/bin
/Library/Frameworks/Python.framework/Versions/3.10/bin
/opt/local/bin
/opt/local/sbin
/usr/local/bin
/System/Cryptexes/App/usr/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Library/TeX/texbin
/opt/X11/bin
/Library/Apple/usr/bin

Because I noticed a problem first through the errors in Spotlight and Apple Mail, I tried to reindex the spotlight search and followed several procedures on the apple forum but none solved my issue.

One of the first things was to properly update the Command Line Developer tools but this did not solve the issues.

Since, I looked into ways of resetting my $PATH and found ways to do it but I don't know which should be my final $PATH to set since I am scarred to mess up other parts of my programming environment with Python and R.

  • If you run the command `ls -l /opt/homebrew/bin/` in a shell, what programs does it list? Does it really list one named `g++-11`? – Some programmer dude Jan 03 '23 at 11:39
  • No, but it gives `31 Nov 25 12:52 g++-12 -> ../Cellar/gcc/12.2.0/bin/g++-12` – jakobjakob Jan 03 '23 at 11:50
  • 1
    It seems the build has an old dependency. You then need to run the configuration part of the build procedure again (whatever that is). If everything else fails, remove the current clone of the project you want to build and reclone it clean. – Ted Lyngmo Jan 03 '23 at 12:06

1 Answers1

0

You should (within your project folder) look for a file named tasks.json this file configures the tasks for your Visual Studio Code. This is an example file I took from a different question I answered some time ago:

{
"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C++: g++ build active file",
        "command": "/usr/bin/g++",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}",

        ],
        "options": {
            "cwd": "${fileDirname}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "Task generated by Debugger."
    }
],
"version": "2.0.0"
}

If you look closely there is a line with an element named "command":

You will most-likely have something like "command": "/opt/homebrew/bin/g++-11" there.

Change it to "command": "/opt/homebrew/bin/g++-12"

EDIT: You can also create a symbolic-link for g++ in your /usr/bin folder that points to your homebrew installation of g++. This should save you a lot of issues when working with VSCode.

Milan Š.
  • 1,353
  • 1
  • 2
  • 11
  • @jakobjakob in that case don't forget to either upvote or mark this as a correct answer. Depending on how much it helped you as per community guidelines. – Milan Š. Jan 03 '23 at 18:59
  • 1
    Thank you for this reminder! It solved everything and the debugging runs smoothly! I marked your comment as accepted! – jakobjakob Jan 09 '23 at 11:26