makefileg++mingw

Error 127 when trying to run a makefile in g++ for Windows


I'm a complete novice who is just now even learning to properly use the command line, so please bear with me. I'm trying to run a program name LATTICEEASY to run simulations for college. I downloaded the program from the official website https://www.felderbooks.com/latticeeasy/download.html and untared it into a folder named latticeeasy2.1; they provide a makefile to create the .exe. I then downloaded the g++ compiler for Windows following this tutorial https://code.visualstudio.com/docs/cpp/config-mingw and set the correct path. I tested it with g++ --version and gcc --version, both were found.

Edit to specify: I ran g++ --version and gcc --version sucessfully in the CMD shell. In the Mingw64 shell, when I tried the same command, it returned -bash: g++: command not found. I figure that is probably the problem? $ start in the Mingw64 shell opens C:\msys64\home\Letícia> in the CMD, and the compilers are in C:\msys64\ucrt64\bin.

I opened a new command prompt through MINGW64 with $ start, cd'ed to the latticeeasy2.1 directory and tried to run make. I got this error:

C:\Users\Letícia\Downloads\latticeeasy2.1>make
g++ -c -O3 ffteasy.cpp
make: g++: No such file or directory
make: *** [Makefile:13: ffteasy.o] Error 127

This is the makefile:

COMPILER = g++
FLAGS = -O3
all: latticeeasy.h model.h parameters.h ffteasy.o latticeeasy.o evolution.o initialize.o output.o
    $(COMPILER) $(FLAGS) ffteasy.o latticeeasy.o evolution.o initialize.o output.o -lm -o latticeeasy

clean:
    rm -f *.o out output.txt latticeeasy *~ *.dat core*

cleaner:
    rm -f *.o out output.txt latticeeasy *~ *.dat *.img

ffteasy.o: ffteasy.cpp
    $(COMPILER) -c $(FLAGS) ffteasy.cpp

latticeeasy.o: latticeeasy.cpp latticeeasy.h model.h parameters.h
    $(COMPILER) -c $(FLAGS) latticeeasy.cpp

evolution.o: evolution.cpp latticeeasy.h model.h parameters.h
    $(COMPILER) -c $(FLAGS) evolution.cpp

initialize.o: initialize.cpp latticeeasy.h model.h parameters.h
    $(COMPILER) -c $(FLAGS) initialize.cpp

output.o: output.cpp latticeeasy.h model.h parameters.h
    $(COMPILER) -c $(FLAGS) output.cpp

I have no idea what is going wrong; the .cpp and .h are all in the same directory as the makefile. I tried copying and pasting all the files to the same directory as the MinGW, but ran into the same error.

Do I have to edit the makefile somehow? This version of LATTICEEASY is from 2007, in case that is relevant.


Solution

  • You are attempting to run make in the wrong MSYS2 environment.

    MSYS2 supports 5 different environments. These boil down to 5 different settings of the PATH environment variable each enabling use of a different variant of either the GCC or the LLVM (clang) toolchain.

    The PATH environment variable is the environment variable whose value is scanned by a shell to find a directory containing the program named by an unqualified command, e.g. $ gcc ..., $ clang ..., so that it can run the command. The value is a list of directories. The PATH variable has the same name and function in the MSYS2 environment and the native Windows environment. It has system-wide and user-wide values in the underlying Windows system and is additionally overridable in individual Windows or MSYS2 shells.

    You have installed the GCC ucrt64-variant toolchain, which you need to access through the MSYS2 UCRT64 shell, but you ran make in the MSYS2 MINGW64 shell, where the PATH does not include your installation directory C:\msys64\ucrt64\bin.

    You need to run make (or any command that calls your GCC ucrt64 toolchain) in the MSYS2 UCRT64 shell. You can find it from the Windows Start menu search box.


    Additionally, it is not necessary to run start in any MSYS2 shell in preparation for using your GCC toolchain, either directly or through GNU make. This merely launches you into a Windows CMD shell within the MSYS2 shell. Your toolchain will run at the MSYS2 prompt, provided the operative PATH lets the shell find it.