none
How to make .obj files to be generated in same folder with source files?

    Question

  • I have a project with multiple classes, and each function in a class is in a separate file in a folder with the same name as the class.

    E.g.

    src\A.cpp contains A() and ~A()

    src\A\run.cpp contains A::run()

     

    Now I have two classes with the same function name. A::run() and B::run() in A\run.cpp and B\run.cpp respectively.

    For some reason Visual C++ 2008 Express Edition defaults to writing all object files in the same folder, which results in one of the run.obj files being overwritten with the other.

    The only "solution" I've found so far has been to manually edit the properties of one of the run.cpp files and make it compile as run2.obj, which is really quite idiotic.

     

    Is there any way I can make the .obj files to be generated in either the same folder with the source code(src\A\run.obj, src\B\b.obj) or automatically in a folder with the same name in the destination directory, as this seems like the only reasonable way this should be done?

     

    Monday, April 26, 2010 11:17 AM

Answers

  • Unfortunately there is no way to do that. The IDE outputs everything to the intermediate build path. There is also no easy way to make that change in VC2008, since you would need to find some variable to depend on to tell it to output to another path.

    This means you are going to end up using an idiotic work around. My suggestion is to name the source files in more sensible ways. So instead of run.cpp, have it named arun.cpp or classarun.cpp. This is going to be less likely to give you problems since you are unlikely to have more than one class named a in your project.


    Visit my (not very good) blog at http://c2kblog.blogspot.com/
    Monday, April 26, 2010 1:43 PM