Operating System - Linux
1753797 Members
8152 Online
108805 Solutions
New Discussion юеВ

How to create the .o file and redirect it to another directory -- Makefile

 
SOLVED
Go to solution
Pedro Dinis
Advisor

How to create the .o file and redirect it to another directory -- Makefile

i have this :

Modelo.o: Modelo.cc Modelo.h
$(CCC) $(CFLAGSCC) -c Modelo.cc


i want the .o file to go ../obj

thanks
SLB SLB SLB Glorioso
8 REPLIES 8
Dennis Handly
Acclaimed Contributor
Solution

Re: How to create the .o file and redirect it to another directory -- Makefile

Then you need to change your rule:
obj/Modelo.o: Modelo.cc Modelo.h
$(CCC) $(CFLAGSCC) -c Modelo.cc -o $@
Dennis Handly
Acclaimed Contributor

Re: How to create the .o file and redirect it to another directory -- Makefile

Oops you had some "..":
../obj/Modelo.o: Modelo.cc Modelo.h
$(CCC) $(CFLAGSCC) -c Modelo.cc -o $@
Pedro Dinis
Advisor

Re: How to create the .o file and redirect it to another directory -- Makefile

i did it like this

Modelo.o: Modelo.cc Modelo.h
$(CCC) $(CFLAGSCC) -c Modelo.cc
cp *.o ../../obj
rm *.o


../obj/Modelo.o:

../obj/Modelo.o: Modelo.cc Modelo.h
$(CCC) $(CFLAGSCC) -c Modelo.cc -o $@


is now calling g++ instead of aCC

[]-pedro:/home/pedro/MODELO_CC>make
g++ -c -o Main_Program.o Main_Program.cc

very strange
SLB SLB SLB Glorioso
Dennis Handly
Acclaimed Contributor

Re: How to create the .o file and redirect it to another directory -- Makefile

>i did it like this

Modelo.o: Modelo.cc Modelo.h
$(CCC) $(CFLAGSCC) -c Modelo.cc
cp *.o ../../obj
rm *.o

I'm not sure why you want to do it like this. This defeats total build avoidance. You should tell the compiler and make exactly where your files are and not have intermediate stages.

../obj/Modelo.o: Modelo.cc Modelo.h
$(CCC) $(CFLAGSCC) -c Modelo.cc -o $@

>is now calling g++ instead of aCC

I'm not sure why? Did you define CCC=aCC?
Pedro Dinis
Advisor

Re: How to create the .o file and redirect it to another directory -- Makefile

yes

CCC = aCC

i am using aCC with OCCI form Oracle

SLB SLB SLB Glorioso
Dennis Handly
Acclaimed Contributor

Re: How to create the .o file and redirect it to another directory -- Makefile

>yes CCC = aCC

That should do it. I'm not sure if make -p would be of any help.
Dennis Handly
Acclaimed Contributor

Re: How to create the .o file and redirect it to another directory -- Makefile

If you have gotten your answers, you should assign points and close the thread.
Pedro Dinis
Advisor

Re: How to create the .o file and redirect it to another directory -- Makefile

done
SLB SLB SLB Glorioso