Search code examples
visual-studiowinapivisual-c++command-line

Visual C++ Command Line Compiler (CL.EXE) Redirect OBJ Files


The compiler (CL.EXE) can take multiple source files, but likes to generate all the OBJ files in the directory that it is invoked. I couldn't find the compiler flag to set an output directory but I did find one for an individual OBJ, but it can't take multiple sources.

Without having to specify each file to redirect the output and having lots of targets for NMAKE, is there an easy way to do it through CL?


Solution

  • It turns out the /Fo option actually works, but the directory you specify must end with a backslash. Thus

    cl  /Fo.\obj\  -c foo.c fee.c
    

    Works but cl /Fo.\obj -c ... would fail.