无法编译代码“启动:程序< program_path>不存在“ [英] Can't compile code "launch: program <program_path> does not exist "
问题描述
我有一个简单的C ++控制台应用程序,可以成功用Visual Studio进行编译.
I have simple console application in C++ that I succeed to compile with Visual Studio.
我想尝试使用Visual Studio Code,所以我将目录复制到安装了Visual Studio Code的计算机上.
我安装了C ++扩展名:
I wanted to try Visual Studio Code so I copied the directory to the computer with Visual Studio Code installed.
I installed the C++ extension:
我将断点放在开头,然后按 F5 ,我收到了错误消息:
I put break point at the beginning and press F5 and I received an error:
启动:程序'输入程序名称,例如 c:\ Users \ student1 \ Desktop \ ConsoleApp \ a.exe'不存在.
launch: program 'enter program name, for example c:\Users\student1\Desktop\ConsoleApp\a.exe' does not exist.
当然该程序不存在,为了使代码成为程序,我正在对其进行编译.
Of course the the program does not exist, I am compiling it in order for the code to become the program.
我按照说明进行操作,然后转到了launch.json
文件:
I followed the instruction and I went to the launch.json
file:
我将"program"
的值更改为:"${workspaceRoot}/a.exe"
而不是"enter program name, for example ${workspaceRoot}/a.exe"
.
I changed the "program"
value to: "${workspaceRoot}/a.exe"
instead of "enter program name, for example ${workspaceRoot}/a.exe"
.
但是同样的问题仍然存在.
任何的想法 ?
But the same problem still exist.
Any idea ?
推荐答案
为此花费了2个小时.
Spent 2 hours on this.
理想情况下,对于初学者来说,VS Code应该不那么困难
Ideally, VS Code shouldn't make so difficult for beginners
VS Code可以像IDEA编辑器那样,逐步,自动地提示每次安装等操作,因此对于初学者而言,这样的过程不会太长.
VS Code can give prompts for each installation, etc. automatically, in a step by step manner, like Idea editors, so that it wont be so long procedure for beginners.
执行步骤的顺序(大多数事情是一次):
Sequence of steps to do (most of the things are one time):
one time:
install a C/C++ complier, add to PATH environment variable
install C/C++ plugin for visual studio code
tell visual studio code where the compiler is and what is the short cut to build and run
these are files under ".vscode" (see below)
every project:
crate a project
build project
run project
详细:
一次:
Note: Point 'A' below can be skipped if you already have a compiler.
A. Install a compiler (if you don't have one already)
Example below, installs MinGW c++ compiler on Windows:
Download from here: https://sourceforge.net/p/mingw-w64/mailman/message/36103143/
1. For windows, I downloaded https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/mingw-w64-v5.0.3.zip
2. unzip mingw-w64-v5.0.3.zip
3. rename unzipped folder to MinGW, Move it to C:\MinGW\
4. verify that you have "C:\MinGW\bin\gcc.exe" director/file, otherwise make necessary change to folder
B. Add your compiler to PATH environment variable
1. Add "C:\MinGW\bin" to PATH > user environment variable
2. verify gcc command works from cmd
restart your cmd
run below command in 'cmd'
where gcc
The output should be: C:\MinGW\bin\gcc.exe
C. Restart your visual studio code
1. install C/C++ plugin, as below:
From Menu
View > Extension
Search & Install below extension
C/C++
每个项目:
注意:您可以每次复制粘贴.vscode文件夹
Note: You can copy paste the .vscode folder every time
A. Create a below "myproj" folder & files, like below in below structure:
C:\myproj\myfile.cpp
C:\myproj\.vscode\
C:\myproj\.vscode\c_cpp_properties.json
C:\myproj\.vscode\launch.json
C:\myproj\.vscode\settings.json
C:\myproj\.vscode\tasks.json
B.下载和从下面的链接覆盖上面的((5个文件))
B. Download & overwrite the above ((5 files)), from below link
https://github .com/manoharreddyporeddy/my-programming-language-notes/tree/master/vscode-c%2B%2B
C. Restart your visual studio/vs code
D. Open project in vs code & run project:
Drag and drop "myproj" folder into visual studio code
BUILD PROJECT: press "Ctrl + Shift + B" to build your myfile.exe
RUN PROJECT: press "Ctrl + F5" to run your myfile.exe
仅此而已,希望对您有所帮助.
Thats all, hope that helped.
更多信息: https://code.visualstudio.com/docs/languages/cpp
可选
更好地格式化C ++
C++ formatting
1. Install Clang:
Download from: http://releases.llvm.org/download.html#5.0.2
I have downloaded for windows
"Pre-Built Binaries:" > Clang for Windows (64-bit) (LLVM-6.0.0-win64.exe)
2. Select Add to PATH while installing.
3. Install vs code plugin "Clang-Format" by xaver, this wraps above exe.
4. Restart visual studio code.
Note:
Issue: As of June 2018, Clang does not format the newer C++17 syntax correctly.
Solution: If so, move that code to another file/ comment & restart the vs code.
That's all. Now press Alt+Shift+F to format (similar key combination in other OS)
这篇关于无法编译代码“启动:程序< program_path>不存在“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!