I have downloaded mingw32 and have it working except I have a problem. I do not want to have to create a new batch file inside the ming32 directory in order to have my program run, If it is possible I would like to just create a Makefile
inside vscode and then have that run.
我已经下载了mingw32,并让它正常工作,除非我有问题。我不想为了让我的程序运行而不得不在ming32目录中创建一个新的批处理文件,如果可能的话,我想只在vscode中创建一个Makefile,然后运行它。
When running the .bat file with the same code as below in the makefile:
使用与Makefile中的代码相同的代码运行.bat文件时:
C:\Users\micha\OneDrive\Visual Studio\CS210\1-Assignment>g++ main.o matrix.o matrices.o helper.o -o exec
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find main.o: No such file or directory
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find matrix.o: No such file or directory
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find matrices.o: No such file or directory
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find helper.o: No such file or directory
collect2.exe: error: ld returned 1 exit status
C:\Users\micha\OneDrive\Visual Studio\CS210\1-Assignment>main.o: main.cpp
'main.o:' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\micha\OneDrive\Visual Studio\CS210\1-Assignment>g++ -c main.cpp
C:\Users\micha\OneDrive\Visual Studio\CS210\1-Assignment>matrix.o: matrix.cpp
'matrix.o:' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\micha\OneDrive\Visual Studio\CS210\1-Assignment>g++ -c matrix.cpp
C:\Users\micha\OneDrive\Visual Studio\CS210\1-Assignment>matrices.o: matrices.cpp
'matrices.o:' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\micha\OneDrive\Visual Studio\CS210\1-Assignment>g++ -c matrices.cpp
C:\Users\micha\OneDrive\Visual Studio\CS210\1-Assignment>helper.o: helper.cpp
'helper.o:' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\micha\OneDrive\Visual Studio\CS210\1-Assignment>g++ -c helper.cpp
C:\Users\micha\OneDrive\Visual Studio\CS210\1-Assignment>clean:
'clean:' is not recognized as an internal or external command,
operable program or batch file.
C:\Users\micha\OneDrive\Visual Studio\CS210\1-Assignment>rm *.o exec
'rm' is not recognized as an internal or external command,
operable program or batch file.
vscode project file explorer image
Vscode项目文件资源管理器图像
the contents of my Makefile
are as follows:
My Makefile的内容如下:
exec: main.o matrix.o matrices.o helper.o
g++ main.o matrix.o matrices.o helper.o -o exec
main.o: main.cpp
g++ -c main.cpp
matrix.o: matrix.cpp
g++ -c matrix.cpp
matrices.o: matrices.cpp
g++ -c matrices.cpp
helper.o: helper.cpp
g++ -c helper.cpp
clean:
rm *.o exec
vscode make setting : directory & path
directory - None
path - make
Vscode生成设置:目录和路径目录-无路径-生成
Below is original post
Good day, I am trying to create a makefile for c++ inside vscode. When running the command 'make' from the terminal i get the following error message:
大家好,我正在尝试为vscode中的c++创建一个Makefile。从终端运行命令‘make’时,我收到以下错误消息:
make : The term 'make' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ make
+ ~~~~
+ CategoryInfo : ObjectNotFound: (make:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I have attempted to install MinGW twice. When installing MinGW I ran the command mingw-get install mingw32-make
in shell, this worked. I then setup my system properties PATH, this also went pretty smoothly. I also created a .exe file inside MinGW bin directory with the following command inside 'mingw32-make.exe $*
.
我尝试安装了两次MinGW。在安装MinGW时,我在shell中运行命令mingw-get install mingw 32-make,这起作用了。然后我设置了我的系统属性PATH,这也进行得很顺利。我还在MinGW bin目录中创建了一个.exe文件,并在'mingw32-make.exe $* 中使用以下命令。
When I returned to vscode I ran make
again; however, this time I got the following error message:
当我返回到vscode时,我再次运行了make;但是,这一次我收到了以下错误消息:
Program 'make.exe' failed to run: The specified executable is not a valid application for this OS platform.At line:1 char:1
+ make
+ ~~~~.
At line:1 char:1
+ make
+ ~~~~
+ CategoryInfo : ResourceUnavailable: (:) [], ApplicationFailedException
+ FullyQualifiedErrorId : NativeCommandFailed
Some side info:
一些附带信息:
The program that I am trying to run is inside my onedrive (if that makes a difference) and vscode is installed into the default directory (C:).
我试图运行的程序在我的OneDrive中(如果这有影响的话),vscode安装到默认目录(C:)中。
I have some extensions installed for vscode, such as cmake etc.
我为vscode安装了一些扩展,如cmake等。
c/c++
c/c++ extention pack
CMake
CMake Tools
Makefile Tools
C/c++c/c++扩展包C生成生成工具生成文件工具
I have tried installed CMake multiple times.
I have tried uninstalled CMake & Makefile Tools
我试过多次安装CMake。我已经尝试过CMCake和Makefile工具
更多回答
Last time I installed Linux from scratch on a new system from the time I booted up a live image stick, to the time I booted a fully installed Linux was about thirty minutes. Another ten minutes to install the latest version of gcc, make, emacs, and a few other libraries. If it took you more than that to painfully try to cram Linux-originated software into an alien operating system, that they weren't originally designed for, and it's still not working correctly, perhaps you should consider cutting your losses and installing Linux?
上一次我在一个新系统上从头开始安装Linux,从我启动一个实时镜像棒到我启动一个完全安装的Linux大约花了30分钟。再花十分钟安装最新版的GCC、make、emacs等几个库。如果你痛苦地试图将源自Linux的软件塞进一个陌生的操作系统中,而这些软件最初并不是为它设计的,而且它仍然无法正常工作,那么也许你应该考虑减少损失,安装Linux?
Sounds like you did not follow the VSCode recommendations and install msys2 and have that install MinGW: https://code.visualstudio.com/docs/cpp/config-mingw If you had done this you would have make installed with MinGW and both would be in the C:\msys64\mingw64\bin
folder.
听起来您没有遵循VSCode的建议,安装了msys2并让它安装了mingw:https://code.visualstudio.com/docs/cpp/config-mingw。如果这样做了,您应该将make与mingw一起安装,并且两者都将位于C:\msys64\mingw64\bin文件夹中。
You should post a separate question about the new issue you're having. Don't edit a second question on top of the first one. (And don't create a dummy make.exe
manually, this is about the worst thing one can do here.)
你应该发布一个关于你遇到的新问题的单独问题。不要在第一个问题上编辑第二个问题。(不要手动创建一个虚拟的Make.exe,这几乎是人们在这里能做的最糟糕的事情了。)
Install make from the msys2 terminal using
使用以下命令从msys2终端安装make
pacman -S make
Then add C:\msys64\usr\bin
to your PATH
然后将C:\msys64\usr\bin添加到您的路径
更多回答
Hello, I did this and it worked for the most part. The problem is that I don't want to have to write a new batch script inside the mingw32 directory. I would like to create a makefile inside vscode and then have it run from there. I'm completely out of the scope of my understanding about this but basically this is what I want to be able to do: Create a program Create a 'Makefile' inside vscode write 'make' inside vscode terminal Have the 'Makefile' execute I am going to add my makefile content in the post above... Please excuse me if im not making any sense
您好,我这样做了,它在很大程度上起作用。问题是,我不想在mingw32目录中编写新的批处理脚本。我想在vscode中创建一个Makefile,然后从那里运行它。我完全超出了我对此的理解范围,但基本上这就是我想要能够做的:创建一个程序,在vscode中创建一个‘Makefile’,在vscode终端中写入‘make’,执行‘Makefile’,我将在上面的帖子中添加我的Makefile内容……如果我没说明白,请原谅
Side note: usr/bin
, if in the PATH, must be after any other MSYS2 paths, such as `mingw64/bin, otherwise weird things can happen.
附注:如果在路径中,usr/bin必须在任何其他MSYS2路径之后,例如`mingw64/bin,否则可能会发生奇怪的事情。
@HolyBlackCat the answer is now a community wiki that others can maintain/improve, this information cannot be found in any official documentation from vscode or mingw or microsoft, so it has to exist here.
@HolyBlackCat答案现在是一个其他人可以维护/改进的社区维基,这些信息在vscode、mingw或微软的任何官方文档中都找不到,所以它必须存在于此。
我是一名优秀的程序员,十分优秀!