X
X
xperious2016-04-24 19:22:19
linux
xperious, 2016-04-24 19:22:19

How to build a program so that the object files are not in the source directory?

Hello, there is a hello.c file in the /hello directory, I created another /hello/arch in this directory... I put the following makefile in it:

all: hpp

hpp : ../hello1.o
  gcc ../hello1.o -o hpp

../hello1.o : ../hello.c
  gcc -c ../hello.c

tell me how to do it right so that the object file is created exactly in /hello/arch, and not in the same directory as hello.c?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Moseychuk, 2016-04-24
@fshp

Replacing "../hello1.o" with "hello1.o"
UPD: The one to the left of the colon is just a label. It has nothing to do with filenames. With the same success, you can write like this:

all: hpp

hpp: compile
        gcc hello.o -o hpp

compile: ../hello.c
        gcc -c ../hello.c

X
xperious, 2016-04-24
@xperious

writes "hello1.o no such file"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question