0

I'm trying to run a simple makefile that looks like this:

T=-ansi -pedantic -Wall -Werror
a.out: test.o extra.o
    gcc $(T) -c test.o extra.o

test.o: test.c test.h 
    gcc $(T) -c test.c

extra.o: extra.c extra.h 
    gcc $(T) -c extra.c

clean:
    rm *.o a.out

But I seem to be getting warnings telling me that "linker input file unused because linking not done"

I tried removing the "-c" from the a.out directive, after the gcc, but that produced to give me more problems. I'm not sure how to go about proceeding from here, any ideas/input would be much appreciated.

EDIT: I'm running the program by "make -T", also removing the -c from a.out, causes the error" invalid symbol index"

4
  • Sorry I'm running it like "make -T", also if I remove the -c, I get the problem "invalid symbol index" Commented Oct 15, 2015 at 0:33
  • See answer...but make -T is odd; what does that do? The 'invalid symbol index' suggests that you should remove all the .o files and run from the start again. Commented Oct 15, 2015 at 0:34
  • My Assigment specifies to use the makefile which is build with the T command (First line in the makefile). Commented Oct 15, 2015 at 0:35
  • make -T doesn't do that...whatever else it does. The T macro is fine; the usage of it is fine. Drop the -T from the command line. (I note that GNU make 3.81 does not recognize -T as a valid option. Either it is new or you are using a different variant of make.) Commented Oct 15, 2015 at 0:36

1 Answer 1

1

You need to remove the -c from the a.out command:

a.out: test.o extra.o
    gcc $(T) test.o extra.o

or, better:

a.out: test.o extra.o
    gcc $(T) -o $@ test.o extra.o

or, still better:

extra: test.o extra.o
    gcc $(T) -o $@ test.o extra.o

The error message is normally because you specify something like -lm on a command line with -c, but you're not doing that here. OTOH, you are listing object files with the -c option — that'll generate the warning:

gcc -ansi -pedantic -Wall -Werror -c test.o extra.o
                                   ^ this one, here

Those .o files are the linker inputs, but you're not linking. Drop the -c and you will generate a.out. That should proceed OK.

I think this is the first time I've seen a makefile used to build a.out. It is unusual in the extreme — not precisely wrong, but definitely not the way you normally use make. It has built-in rules to build programs from single source files, such as example from example.c. Normally, you give a program a meaningful name based on one of the source files. Note that creating a program test is usually a bad idea; there is a standard test command built into the typical shell and confusion is rampant.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.