You are not logged in.

#1 2009-07-05 11:01:10

praavDa
Member
Registered: 2008-08-21
Posts: 34

GCC: different output directory for bin / obj files

Hello,

Few days before I started playing with GCC and C++. I'm using VIM as my IDE, so I have to write my own makefiles - and I have a little problem with this one.

You see, I wanted so my usual project structure would look like this one:

Project/:
    /bin           - directory with binary and object files for my project.
    /src           - directory with source files for my project


I am calling gcc from within src directory - is there any way, so I can force outputting all object files and binary files into /bin directory?

As for now, my sample makefile looks like this:

CXX=g++
CXXFLAGS=-s -O3
OBJS=ArrayArguments.o

ArrayArguments : $(OBJS)
    $(CXX) $^ -o $@

%.o : %.c
    $(CXX) -c $(CXXFLAGS) $< -o $@

clean:
    rm -f *.o

In VIM, I have following command attached to F8 key:

map <F8> : call CompileGcc()<CR>
func! CompileGcc()
  exec "w!"
  exec "make"
endfunc

If anyone could post some guidelines or maybe some links to resources about basic usages of GCC so I could find the solution on my own - I would be grateful.

cheers,
praavDa.


gvim -c "exec \"normal itYNQ#v'Z#ABG#GUR#BAYL#BAR\"|%s/#/ /g|normal ggVGg?ggVG~"

Offline

#2 2009-07-05 13:42:02

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: GCC: different output directory for bin / obj files

Sure, it's all about how you write your Makefile targets - a slight modification to your current Makefile should work.

CXX=g++
CXXFLAGS=-s -O3
OBJS=ArrayArguments.o
OUT_DIR=/bin
OUT_OBJS=$(addprefix $(OUT_DIR)/,$(OBJS))

ArrayArguments : $(OUT_OBJS)
    $(CXX) $^ -o $@

%(OUT_DIR)/%.o : %.c
    $(CXX) -c $(CXXFLAGS) $< -o $@

clean:
    rm -f $(OUT_DIR)/*.o

Offline

Board footer

Powered by FluxBB