AWTom
AWTom

Reputation: 5

Make is running old/broken commands

I'm running Lubuntu 12.10. My make file is named makefile and looks like this:

all: SquaresTesting.o Vector2d.o
    clang -o SquaresTesting SquaresTesting.o

SpringTesting.o: SquaresTesting.cpp
    clang -c SquaresTesting.cpp

Vector2d.o: Vector2d.cpp Vector2d.h
    clang -c Vector2d.cpp

I am in the same directory as that file but when I do make, it runs g++ -c -o SquaresTesting.o SquaresTesting.cpp (there are four spaces between g++ and -c; I've never done anything like that). It seems like changes aren't saving. I'm thinking either make crashed, my editor Geany done goofed, the filesystem is weird, or my SSD is corrupt.

Upvotes: 0

Views: 87

Answers (1)

MadScientist
MadScientist

Reputation: 100956

Your editor may have goofed or your filesystem might be weird or your SSD might be corrupt, but I typically find that when something doesn't work right the problem is most often that I made a mistake :-).

In this case, you have mistyped your target:

SpringTesting.o: SquaresTesting.cpp

You have told make that this rule will create SpringTesting.o. But make is trying to find a way to make SquaresTesting.o. Since you have no rule to build SquaresTesting.o, make tries to find one, and it does find one: there's a built-in rule to build any .o from a .cpp, and there does happen to be a SquaresTesting.cpp right there.

And since the default configuration for the C++ compiler is g++, that's what it uses.

If you fix your target to say:

SquaresTesting.o: SquaresTesting.cpp

you should be all set. Of course, you could also take advantage of make's built-in rules; your entire makefile could be written as:

CXX = clang

all: SquaresTesting

SquaresTesting: SquaresTesting.o Vector2d.o

I'm assuming here that you wanted to link Vector2d.o as well, although your makefile doesn't show that.

Upvotes: 1

Related Questions