Edit

Share via


/Fo (Object File Name)

Specifies an object (.obj) file name or directory to be used instead of the default.

Syntax

/Fo"pathname"
/Fo:[ ]"pathname"

Remarks

You can use the /Fo compiler option to set an output directory for all the object files generated by the CL compiler command. Or, you can use it to rename a single object file. Don't put a space between the /Fo option and the pathname argument.

By default, the object files generated by the compiler are placed in the current directory. They're given the base name of the source file and a .obj extension.

To use the /Fo option to rename an object file, specify the output filename as the pathname argument. When you rename an object file, you can use any name and extension you want, but the recommended convention is to use an .obj extension. The compiler generates command line error D8036 if you specify a filename to /Fo when you've specified more than one source file to compile.

To use the /Fo option to set an output directory for all object files created by the CL command, specify the directory as the pathname argument. A directory is indicated by a trailing slash or backslash in the pathname argument. Use an escaped backslash (a double backslash), if you're using a quoted path. The directory path can be absolute, or relative to the source directory. The specified directory must exist, or the compiler reports error D8003. The directory isn't created automatically.

Example

This command line demonstrates the format that allows for an optional space between the /Fo option and the pathname argument. It creates an object file named test.obj in the current directory.

CL /Fo: "test" /EHsc /c sample1.cpp

The following command line creates object files named sample1.obj and sample2.obj in an existing directory, D:\intermediate\. It uses escaped backslash characters as path segment separators in a quoted path:

CL /Fo"D:\\intermediate\\" /EHsc /c sample1.cpp sample2.cpp

This command line creates object files named sample1.obj and sample2.obj in an existing directory, output\, relative to the source directory.

CL /Fooutput\ /EHsc /c sample1.cpp sample2.cpp

Set the option in Visual Studio or programmatically

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.

  2. Select the Configuration Properties > C/C++ > Output Files property page.

  3. Modify the Object File Name property to set the output directory. In the IDE, the object files must have an extension of .obj.

To set this compiler option programmatically

See also

Output-file (/F) options
MSVC compiler options
MSVC compiler command-line syntax
Specifying the pathname