Can Git Bash for Windows run user-compiled Windows apps?

Viewed 39

I am trying out C++ compilation in Windows 10 using VSCode as editor, MSYS2 as package manager and environment, MSYS2's mingw32-make as build system and MSYS2's g++ as compiler. To run the tools in the toolchain I'm using a Git Bash shell terminal in VSCode (mostly to avoid dealing with cmd/Powershell syntax) and I managed to build a minimal HelloWorld application, but I cannot run the generated exe file in the Git Bash shell : when running bin/helloworld.exe in the Git Bash shell I get no output at all. I can run the app flawlessly in a cmd terminal by running bin\helloworld.exe, so I am not sure what I may be missing or if it is even possible. I would prefer to keep using just one Unix like shell instead of hopping between bash and cmd.

Source code:

main.cpp

#include "myClass.h"

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};

    for (const string& word : msg)
    {
        cout << word << " ";
    }
    cout << endl;
    myClass someObject;
    someObject.print();
}

myClass.h

class myClass
{
public:
  void print() const;

private:
  int m_someValue = 0;
};

myClass.cpp

#include "myClass.h"

#include <iostream>

void
myClass::print() const
{
  std::cout << m_someValue << std::endl;
}

Makefile

CC=g++

EXECUTABLE_NAME=helloworld
BIN_DIR=bin
SRC_DIR=src
OBJ_DIR=out

SOURCE_FILES     = $(wildcard $(SRC_DIR)/*.cpp)
EXECUTABLE_FILES = $(EXECUTABLE_NAME:%=$(BIN_DIR)/%)
OBJECT_FILES     = $(SOURCE_FILES:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)

# Debugger rule for printing variables
print-%  : ; @echo $* = $($*)

build: $(EXECUTABLE_FILES)

clean:
    rm -f $(EXECUTABLE_FILES) $(OBJECT_FILES)

.PHONY: build clean

$(EXECUTABLE_FILES): $(OBJECT_FILES)
    @mkdir -p $(BIN_DIR)
    $(CC) $(LDFLAGS) -o $@ $^
    @echo "Build successful!"

$(OBJECT_FILES): $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
    @echo Compiling $<
    @mkdir -p $(@D)
    $(CC) $(CFLAGS) -o $@ -c $<
0 Answers
Related