Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 564
Jasoneer Avatar asked Oct 09 '11 20:10

Jasoneer


People also ask

What is CL in command line?

CL passes these options to the linker. You can specify any number of options, filenames, and library names, as long as the number of characters on the command line does not exceed 1024, the limit dictated by the operating system.

What is CL exe in Visual Studio?

cl.exe is a tool that controls the Microsoft C++ (MSVC) C and C++ compilers and linker. cl.exe can be run only on operating systems that support Microsoft Visual Studio for Windows. Note. You can start this tool only from a Visual Studio developer command prompt.

How do I view OBJ files in Visual Studio?

You can use Visual Studio 'Tools / Options / Text Editor / Extensions / Add Extension: (OBJ, Visual Studio C++) Then every . obj will open as a text file.

Where is Cl exe stored?

cl.exe is usually located at %VCINSTALLDIR%\bin\ . VCINSTALLDIR environment variable is not set by default, but it is being set when you open Visual Studio's Native Tools Command Prompt.


1 Answers

Just to add to the only answer. In case when the obj path is quoted, the trailing backslash has to be either added after the path closing quote, or escaped if added before the quote.

cl  /Fo"quoted path\obj"\  -c foo.c fee.c

OR

cl  "/Foquoted path\obj"\  -c foo.c fee.c

OR

cl  /Fo"quoted path\obj\\"  -c foo.c fee.c

Speaking of NMAKE, similar syntax is expected when passing quoted macro values on NMAKE command line. The trailing backslash seems to be the crucial bit to watch for.

nmake SOMEDIR="quoted path\obj"\

OR

nmake SOMEDIR="quoted path\obj\\"

OR

nmake "SOMEDIR=quoted path\obj"

NOT

nmake SOMEDIR="quoted path\obj\"

as this would result in an escaped quote \" and would grab whatever else followed on the command line and put it into $(SOMEDIR). Took me a while to diagnose such a behavior, hope this would save time to someone else.

like image 88
commanDOS Avatar answered Sep 21 '22 23:09

commanDOS