microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.52k stars 1.55k forks source link

Use `/Fe<file>` (single arg) syntax when generating `tasks.json` to support older versions of `cl.exe` #8493

Closed toninlg closed 2 years ago

toninlg commented 2 years ago

Bug type: Language Service

Describe the bug

main.c

LINK : fatal error LNK1181: cannot open input file 'C:\Home\Public\test\main.exe'

Build finished successfully.


**Expected behavior**
Correct detection of cl.exe and paths. Successful build and coherent output message, why is the build finished successfully?

- Configurations in `c_cpp_properties.json` after manual settings of compilerpath and includepath

{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**", "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "cStandard": "c89", "cppStandard": "c++98", "intelliSenseMode": "windows-msvc-x86", "compilerPath": "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\cl.exe" } ], "version": 4 }


- generated tasks.json

{ "type": "cppbuild", "label": "C/C++: cl.exe build active file", "command": "cl.exe", "args": [ "/Zi", "/EHsc", "/nologo", "/Fe:", "${fileDirname}\${fileBasenameNoExtension}.exe", "${file}" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$msCompile" ], "group": { "kind": "build", "isDefault": true }, "detail": "compiler: cl.exe" }

Colengms commented 2 years ago

Hi @toninlg . I recommend installing a recent version of Visual Studio instead of "Windows SDK 7.1". It looks like you are trying to use a version of cl.exe included with Visual Studio 2010, which is rather old and no longer supported by the C/C++ extension for VS Code.

I assume you used the build and debug active file feature of the C/C++ extension, to generate your tasks.json. It looks like the /Fe: arg was not supported in that older version of cl.exe. I suspect you could modify your tasks.json by removing the /Fe: and subsequent arg. However, for the best experience, I'd suggest installing a more recent version of Visual Studio, such as Visual Studio 2022 Community Edition.

toninlg commented 2 years ago

Hi. I used "Configure default build task" from terminal to generate tasks.json. On newer compiler :

VSCode

Colengms commented 2 years ago

Hi @toninlg . We could make a change to use the /Fe<file> syntax whenever generating a tasks.json, to support older compilers.

The tasks.json is used to essentially just issue a command line. If you run the same command line directly, you should get the same result. Can you determine what the correct command line is to successfully compile and link with the compiler you are using? If you could let me know what that is, I could investigate making changes to how the tasks.json is generated, to accommodate.

toninlg commented 2 years ago

Here is the modification I had to do to compile with Windows SDK 7.1 (SDK version is not picked up and not recognized because of the regex but it's the version number given by WindowsSdkVer.exe, so LIBPATH has to be set to find kernel32.lib):

github-actions[bot] commented 2 years ago

Hey @Colengms, this issue might need further attention.

@toninlg, you can help us out by closing this issue if the problem no longer exists, or adding more information.