# organize project and specify directory for object files in Makefile

This is a discussion on organize project and specify directory for object files in Makefile within the C++ Programming forums, part of the General Programming Boards category; Hi, Here are my two questions: 1. I am now learning to manage my code with CVS, and I just ...

1. ## organize project and specify directory for object files in Makefile

Hi,
Here are my two questions:

1. I am now learning to manage my code with CVS, and I just want to make a repository for my C++ files, Makefile and bash and python scripts only, not the object files and executables. So I made several subdirectories under my project directory: src, bin, scripts, results and data. I put C++ files and Makefile under ~/myproject/src, bash and python scripts under ~/myproject/scripts and object and executables under ~/myproject/bin. I am hoping only the files under src and scripts will be updated via CVS. I wonder how you guys organize your projects? Just hope to follow some good habits

2. Since I put my C++ files and Makefile into ~/myproject/src and object and executable files into ~/myproject/bin, I have to specify the directories in Makefile. Here is what I am doing
Code:
...
BIN_DIR=/home/myproject/bin/

all: $(BIN_DIR)myexecutable TAGS TAGS: *.cc *.h etags --members --declarations -l c++ *.cc *.h$(BIN_DIR)myexecutable: $(BIN_DIR)myobject.o$(CXX) $(CXXFLAGS) -o$@ $^$(LDFLAGS)

Makefile.depend: *.h *.cc Makefile
$(CXX) -M$(CXXFLAGS) *.cc > Makefile.depend

clean:
\rm -f $(BIN_DIR)myexecutable$(BIN_DIR)*.o Makefile.depend TAGS
However this will give error
make: *** No rule to make target /home/myproject/bin/myobject.o', needed by /home/myproject/bin/myexecutable'.
How to specify a different directory for object and executable files from C++ files in Makefile?

Thanks and regards!

2. What's the problem? "myobject.o" is a dependency, but you do not have a make rule for it. It isn't being compiled. Add a rule and it's fixed.

3. I think
Code:
$(CXX)$(CXXFLAGS) -o $@$^ \$(LDFLAGS)
is to generate the object files from C++ files. But how to specify that I want the object files to be generated under /home/myproject/bin?