Issue
I need to pass the arg -Wl,-Bstatic,--whole-archive to g++.
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "shell: g++.exe build active file",
"command": "C:\\MinGW\\x86\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-Wl,-Bstatic,--whole-archive",
"-Xlinker",
"-Map=${fileDirname}\\${fileBasenameNoExtension}.map",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MinGW\\x86\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
It gives me in output this in the terminal.
Executing task: C:\MinGW\x86\bin\g++.exe -g 'c:\Users\remi\Desktop\OK - VSCode\loaderstack.cpp' -Wl,-Bstatic,--whole-archive -Xlinker '-Map=c:\Users\remi\Desktop\OK - VSCode\loaderstack.map' -o 'c:\Users\remi\Desktop\OK - VSCode\loaderstack.exe' <
At line:1 char:84
+ ... e -g 'c:\Users\remi\Desktop\OK - VSCode\loaderstack.cpp' -Wl,-Bstatic ...
+ ~
Missing argument in parameter list.
At line:1 char:93
+ ... Users\remi\Desktop\OK - VSCode\loaderstack.cpp' -Wl,-Bstatic,--whole- ...
+ ~
Missing argument in parameter list.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingArgument
Is there anyway to build inside VSCode with these comma-separated args ?
Solution
I originally answered this question (like a dumb dumb) as if you were using Linux, so I deleted that answer and included a new one for PowerShell.
This is sort of a common problem when dev's use GCC with Powershell. The problem is that PowerShell is very programmatic in the way it implements its interface, and the way that it executes commands. With Linux, CLI's are all written opensource (mostly) and are developed by the developers, where powershell is created by a company that dictates how every little detail works (there are benefits, and downsides to both). PowerShell has aspects/features (or w/e you want to call them) that just feel like somthing a programming language has, for example PowerShell has scopes, and what you pass to powershell gets parsed according to the context (or scope) that your currently in. The problem you are dealing with is that your command, that your handing GCC through your VS Code v2 Task is not being parsed properly due to the context in which the task is handing it to Power-shell.
YOU HAVE 2 OPTIONS
Option #1
The first option is to use a scope where the parser will correctly interoperate the command.
Remember, your using a VSCode task, powershell & gcc, to make sure communication succeeds across all three, you need to include the scope to use in what you are communicating. To do that we want to make use of the...
Call Operator &
To use the call operator just format the initial command to execute as shown in the code block bellow:
"command": "& C:\\MinGW\\x86\\bin\\g++.exe",
Where I know that this is a valid solution to your problem, I am currently on a Linux System, I have windows dual booted, but I am too lazy to switch over to it, so just in-case something needs to be tweaked, use the link for the Call Operator I posted above, MS documentation is very good, and very specific about how to implement its software-technologies
Option #2
Your second option takes a totally different route than the first.
Instead of dealing with the scope being the problem, your gonna deal with Power-shell's inability to parse the MingW GCC Command.
To deal with Power-shell's parsing issue, we will tell it to stop parsing the command, henceforth, the...
stop-parsing flag --%
(For the semantics police-type of developers: I think its technically a token, not a flag)
Using the flag looks like this: gcc %--
So the whole command should look somthing like this:
"args": [
"--%"
"-g",
"${file}",
"-Wl,-Bstatic,--whole-archive",
"-Xlinker",
"-Map=${fileDirname}\\${fileBasenameNoExtension}.map",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
Again, I included the link to the docs for the stop-parsing token above, just in-case something needs to be tweaked.
The example I showed above is somthing I had to use on a project that I worked on for a very long time, because of that experiance, I perfer to use the no
Somthing else that I don't know much about, by I read about when I DDG'd the links to Microsoft-site that might, maybe work is using the Arguments mode, which seems to be similar to the stop parsing command?
Anyhow, here is the link if you want to read about it.
Answered By - J-D3V Answer Checked By - Willingham (WPSolving Volunteer)