views:

573

answers:

1

Hi, I have a c++ Makefileproject for eclipse, if I build it, the binary is in the project root. How can I change the build directory to {ROOT}/bin?

I Tryed project propertys -> c/c++ Build -> Build location (Build directory: MY PATH) but than it can't compile at all.

+4  A: 

You use a Makefile-Project. Everything that has to be done, including where to put an executable, has to be coded into the Makefile by you! Eclipse just kicks the build by invoking make.

An simple example:

CXXFLAGS= -g -O0
CXX=g++


all: bin bin/test

bin/test: bin/test.o
    $(CXX) -o bin/test bin/test.o

bin/test.o: test.cpp
    $(CXX) $(CXXFLAGS) -o bin/test.o -c test.cpp

bin:
    mkdir bin

clean:
    rm bin/test.o
    rm bin/test

This is the source I learned how to write a Makefile from: http://www.eng.hawaii.edu/Tutor/Make

Plain Makefiles are handy for projects with a small number of files. Once you've been bitten by having a segfault due to missing recompilaton (forgot to list a header file at the .o: dependencies) you should move on to a full blown build system, like cmake. cmake generates Makefiles for you, but its important to understand the fundamentals of Makfiles to interpret error messages.

Maik Beckmann