VSC tasks.json causing confusing executable name

Hi - great course here by the way. Having a lot of fun. I keep seeing this confusing issue:

The main.cpp is there as usual, and also the file main which is the expected output binary. However there’s also these other binaries, like Enemy. What is going on?

I see people posting about build files not updating and other issues. Their problems are usually closed, can’t reproduce.

VSC Compiler not showing animation but .exe does7hmyo5_gaMjAzNjAyNTg2NS4xNzAyNjI3MDg0_ga_2C81L26GR9*MTcwNDk0Njc2NC41Mi4wLjE3MDQ5NDY3NjQuMC4wLjA.

Well, I figured it out. Whichever file you have selected in VS Code will get fed in via the ${fileBasenameNoExtension} parameter to the Makefile as PROJECT_NAME because the file .vscode/tasks.json has this code:

          "osx": {
                "args": [
                    "PROJECT_NAME=${fileBasenameNoExtension}",
                    "OBJS=*.cpp"
                ]
            },

This is harmless enough when the early lessons did not have multiple files. But now there’s new files like Enemy.cpp depending on what file you randomly happened to have edited last when you did ⇧⌘ B to invoke the default build task, you will get a differently name binary.

This can mean that you run a binary that hasn’t got the changes you just made because those changes went into Enemy binary when you are trying to run the main binary.

I’m just going to modify my .vscode/tasks.json to set the PROJECT_NAME to be the same as the folder - since I named my folder ClassyClash which is a good executable name.

But you could just hard code it to MyGame or something.

It looks like this:

          "osx": {
                "args": [
                    "PROJECT_NAME=${workspaceFolderBasename}",
                    "OBJS=*.cpp"
                ]
            },

I also had to update the file .vscod/launch.json to set the program name as well for the Debug launch configuration so that using VSCode’s debug setting would work:

          "name": "Debug",
          "type": "cppdbg",
          "request": "launch",
          "program": "${workspaceFolder}/${workspaceFolderBasename}",
          "args": [],

Privacy & Terms