a1s2d3f4
a1s2d3f4

Reputation: 619

visual studio compiler how to specify the include path to build cpp

I am using a batch file to try to build my cpp program using Visual Studio's cl.exe. This is what it contains:

"C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\cl.exe" /I "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\" "%1" /Fe "%1.exe"

I want to the compiler to include iostream from the include folder and build my .cpp (%1) as %1.exe.

Instead, I get:

Microsoft (R) C/C++ Optimizing Compiler Version 17.00.60610.1 for x86 Copyright (C) Microsoft Corporation. All rights reserved.

cl : Command line error D8003 : missing source filename

What am I doing wrong?

Win8.1 x64

Upvotes: 6

Views: 19288

Answers (3)

Innokentii Smirnov
Innokentii Smirnov

Reputation: 1

I use the following Notepad++ command to compile Visual C++:

cmd /k "D:\Programs\VC\VC\Auxiliary\Build\vcvarsall.bat x86 & cd /d $(CURRENT_DIRECTORY) & cl $(FILE_NAME) & $(NAME_PART).exe"

"D:\Programs\VC" should be replaced by the path to Visual Studio Build Tools on your system; the second "VC" and what follows remains. The vcvarsall.bat script with x86 argument (the argument depends on your system) sets the necessary variables and allows the compiler to find its libraries. This script ships with Visual Studio and is adjusted to your system during its installation.

& $(NAME_PART).exe is not necessary, it runs the compiled program.

Note also that I have the directory with cl.exe on PATH.

Upvotes: 0

a1s2d3f4
a1s2d3f4

Reputation: 619

Answer:

  • Get rid of the backslash at the end of the include path (...\...\include")

  • Do not surround %1 with quotes

  • no space between /Fe and ":

    "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\cl.exe" /I "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include" %1 /Fe"%1.exe"

Upvotes: 10

Robert Altena
Robert Altena

Reputation: 795

Do not run cl.exe from a standard command prompt. Use the "Developer Command Prompt" installed with VS 2015. This sets several environment variables for you, specific to your installation.

To read more: https://msdn.microsoft.com/en-us/library/f35ctcxw.aspx

Upvotes: 0

Related Questions