Makefile Not Finding Rule
Hello all,
I am having some trouble getting Make to work properly.
I am trying to follow this tutorial:
Getting started with Google Test (GTest) on Ubuntu – Erik Smistad
But I am trying to adapt it to work with make. I broke the whattotest.cpp file into a header file and added a more normal directory structure.
Folder PATH listing for volume D
Volume serial number is 1A80-3041
D:.
│ makefile
│ Notes.txt
│
├───bin
│ .dirstamp
│
├───inc
│ whattotest.hpp
│
├───obj
│ .dirstamp
│
├───src
│ whattotest.cpp
│
└───tests
tests.cpp
whattotest.hpp
Code:
#pragma once
#include <math.h>
double squareRoot(const double a);
whattotest.cpp
Code:
// whattotest.cpp
#include <math.h>
#include "whattotest.hpp"
double squareRoot(const double a) {
double b = sqrt(a);
if(b != b) { // nan check
return -1.0;
}else{
return sqrt(a);
}
}
tests.cpp
Code:
// tests.cpp
#include "whattotest.hpp"
#include <gtest/gtest.h>
TEST(SquareRootTest, PositiveNos) {
ASSERT_EQ(6, squareRoot(36.0));
ASSERT_EQ(18.0, squareRoot(324.0));
ASSERT_EQ(25.4, squareRoot(645.16));
ASSERT_EQ(0, squareRoot(0.0));
}
TEST(SquareRootTest, NegativeNos) {
ASSERT_EQ(-1.0, squareRoot(-15.0));
ASSERT_EQ(-1.0, squareRoot(-0.2));
}
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
makefile
Code:
CXX = g++
BLDDIR = bin
SRCDIR = src
INCDIR = inc
OBJDIR = obj
TESTDIR = tests
CPPFLAGS = -Iinc
LXXFLAGS = -lgtest -lpthread
GTEST = C:\MinGW\lib\libgtest.a
.PHONY: all
all: $(BLDDIR)/.dirstamp $(OBJDIR)/.dirstamp $(TESTDIR)/runTests
$(BLDDIR)/.dirstamp:
mkdir -p $(BLDDIR)
touch $(BLDDIR)/.dirstamp
$(OBJDIR)/.dirstamp:
mkdir -p $(OBJDIR)
touch $(OBJDIR)/.dirstamp
$(TESTDIR)/runTests: $(OBJDIR)/tests.o $(OBJDIR)/whattotest.o $(GTEST)
$(CXX) $(LXXFLAGS) -g $^ -o $@
$(OBJDIR)/tests.o: $(TESTDIR)/tests.cpp
$(CXX) $(CPPFLAGS) -c $< -o $@
$(OBJDIR)/whattottest.o: $(SRCDIR)/whattottest.cpp
$(CXX) $(CPPFLAGS) -c $< -o $@
.PHONY: clean
clean:
rm $(BLDDIR)/*
rm $(OBJDIR)/*.*
rm $(TESTDIR)/runTests
Make is failing this for:
make: *** No rule to make target 'obj/whattotest.o', needed by 'tests/runTests'. Stop.
What am I missing?
Thank you for the response!
Hi Salem,
Thank you for the response.
The GTEST is actually just a make variable.
But, to your point, I tried adding -LC:\MinGW\lib\libgtest.a to the linker flags. This still results in undefined errors for the googletest methods.
Placing the gtest and gmock folders in the compiler directories was part of the instructions I had found for installing google test on windows.
The weird thing is this was all working just fine until I had to upgrade my compiler, and like you said everything stopped working.
But, I have re-installed the exact same way(I took detailed notes the first time because it was a nightmare) and now it doesn't work.
I will try using your -L<path> and -l<moduleName> technique and and try pointing to where I unzipped GoogleTest. God I hope that works.