0

(Disclaimer: I am not at all a computer science genius, far from that. I may use bad terminology and I appologize.)

I need to run some tests using the google test library and I was provided with a Makefile to handle the execution but it won't run on my Windows machine (I use Visual Studio). It was made for a Linux environment so I'm not sure what i would need to modify in order to run it. I have used MinGW to run Makefiles of my own making in the past.

Here's how the Makefile looks like:

CC=g++
CFLAGS=-c -Wall -ggdb -I.
LDFLAGS=
SOURCES=main.c singlelinklist.c
TESTS=single_test.cpp


#TODO: Need a more elegant way of specifying objects and tests
GTESTDIR=~/environment/googletest
OBJECTS=$(SOURCES:.cpp=.o)

FLAGS   = -Iinclude

#all: $(SOURCES) $(EXECUTABLE)
    

# These next lines do a bit of magic found from http://stackoverflow.com/questions/2394609/makefile-header-dependencies
# Essentially it asks the compiler to read the .cpp files and generate the needed .h dependencies.
# This way if any .h file changes the correct .cpp files will be recompiled
depend: .depend

.depend: $(SOURCES)
    rm -f ./.depend
    $(CC) $(CFLAGS) -MM $^ >> ./.depend;

include .depend
# End .h file magic

#$(EXECUTABLE): $(OBJECTS) 
#   $(CC) $(LDFLAGS) $(OBJECTS) -o $@

#.cpp.o:
#   $(CC) $(CFLAGS) $< -o $@

clean:
#   rm -rf *o $(EXECUTABLE) test_executable
    rm -f ./.depend
    rm $(GTESTDIR)/libgtest.a
    rm $(GTESTDIR)/gtest-all.o

# Google test section
$(GTESTDIR)/libgtest.a: 
    $(CC) -isystem $(GTESTDIR) -I $(GTESTDIR) -pthread -c $(GTESTDIR)/gtest/gtest-all.cc -o $(GTESTDIR)/gtest-all.o
    ar -rv $(GTESTDIR)/libgtest.a $(GTESTDIR)/gtest-all.o

# This will also recompile if any source file is changed.
test_executable: $(GTESTDIR)/libgtest.a $(TESTS) depend
    $(CC) -isystem $(GTESTDIR) -pthread -ggdb $(TESTS) $(GTESTDIR)/gtest/gtest_main.cc $(GTESTDIR)/libgtest.a -o test_executable

test: test_executable
    ./test_executable --gtest_print_time=0

And here's how my workspace is structured.

enter image description here

(Seems like I can't embed pictures).

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • 1
    To make makefiles work, you need `make` in 1st place. You can install MinGW, which comes with all the tools available with the GNU compiler toolchain. – πάντα ῥεῖ Oct 10 '20 at 14:54
  • I have done that but i keep running in this error I forgot to mention C:\Users\X\Desktop\CSCI 240 Homework 5 X>mingw32-make Makefile:26: .depend: No such file or directory rm -f ./.depend process_begin: CreateProcess(NULL, rm -f ./.depend, ...) failed. make (e=2): The system cannot find the file specified. Makefile:23: recipe for target '.depend' failed mingw32-make: *** [.depend] Error 2 – Xu Dank Oct 10 '20 at 15:14
  • Do you have the MinGW bin directory in your PATH environment variable? – πάντα ῥεῖ Oct 10 '20 at 15:17
  • I'm not sure how I would check that. – Xu Dank Oct 10 '20 at 15:22
  • Goto windows system control, extended settings environment variables. – πάντα ῥεῖ Oct 10 '20 at 15:26
  • Yes it is in my environment variables. – Xu Dank Oct 10 '20 at 15:37
  • Does this answer your question? [How to run .sh on Windows Command Prompt?](https://stackoverflow.com/questions/26522789/how-to-run-sh-on-windows-command-prompt) – tripleee Oct 12 '20 at 10:58

0 Answers0