Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Makefile and object file locations

Status
Not open for further replies.

WebDrake

Programmer
Sep 29, 2005
106
PL
Further to my previous question about modularizing code, when I want to compile source to object files, is there any way of determining where the object files are located?

e.g. gcc -c [all the source files] just produces objects in the present directory.

But suppose I wanted to put all the object files for a project into a special directory, how would I do that?

Many thanks,

-- Joe
 
The -o switch allows you to control the outputted file name/location.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Thanks; but I don't quite get how to use the vpath directive (which looks like the one I need). Suppose that my libraries are all in /code/src/ and I denote by SRC the string of all source code names.

Then, I might put,

vpath %.c /code/src/

But my later compile command,

gcc -c $(SRC)

obviously only looks in the current directory. How do I alter the latter to take advantage of vpath?

Thanks,

-- Joe
 
Hmm, let's get specific. Here's my Makefile:

Code:
VPATH = /home/joecode/src/:./o/

SRC = n0.c neuR0/neuR0.c RAN.c Xhist/Xhist.c graphs/GRIDgraph.c graphs/randomgraph.c graphs/addlink.c
OBJ = n0.o neuR0.o RAN.o Xhist.o GRIDgraph.o randomgraph.o addlink.o
PROG = n0
CC = icc
FLAGS = -O3 -Ob2 -ip -ipo

$(PROG): $(OBJ)
	$(CC) $(FLAGS) $^ -o $(PROG)

$(OBJ): $(SRC)
	$(CC) $(FLAGS) -c $^
	mv *.o ./o/

The idea is that all .o files should be in the directory ./o/ before the code will try to compile them. This code produces errors---the makefile is unable to find the copied *.o files. What's wrong? :p

Thanks,

-- Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top