Search code examples
c++makefile

The term 'make' is not recognized as the name of a cmdlet


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.

When running the .bat file with the same code as below in the makefile:

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

the contents of my Makefile are as follows:

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

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:

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 $*.

When I returned to vscode I ran make again; however, this time I got the following error message:

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:).

I have some extensions installed for vscode, such as cmake etc.

c/c++ c/c++ extention pack CMake CMake Tools Makefile Tools

I have tried installed CMake multiple times. I have tried uninstalled CMake & Makefile Tools


Solution

  • Install make from the msys2 terminal using

    pacman -S make
    

    Then add C:\msys64\usr\bin to your PATH