6

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

a1s2d3f4
  • 589
  • 4
  • 7
  • 18
  • 1
    While you certainly also can do that, why not use MSBuild on the .vcproj of your application to build it? – BitTickler Jul 14 '15 at 00:59
  • 1
    Just a shot in the dark, but I suspect you may have to use "%%" where you just want "%". The command line acts that way sometimes. – Logicrat Jul 14 '15 at 01:00
  • @Logicrat %% is used inside a batch file to create a literal %. See http://stackoverflow.com/questions/14509652/what-is-the-difference-between-and-in-a-cmd-file for instance. – a1s2d3f4 Jul 14 '15 at 03:13
  • @BitTickler. I don't want to use .vcproj. I just want to use my notepad++ to write basic code, like I used to when compiling with bcc32 (borland) just yesterday and not be tied into some new "environment". I just want to understand how to tell cl.exe where all my includes are, .libs and all those things and be able to compile with one command line execution. So, how can I do it - what am I doing wrong? – a1s2d3f4 Jul 14 '15 at 03:13
  • @a1s2d3f4 What you seem to say is: "I want MORE work. Less support. No debugging. No syntax highlighing. Absolutely NO code completion. No static code checker... I want to suffer - big time!" Well - to each their own. Have fun with that :) – BitTickler Jul 14 '15 at 04:16
  • @BitTickler Actually, I was thinking of "less" work. As I mentioned, I can compile with bcc32. I would provide my bcc-related batch file with the name of the main cpp and get back an .exe in my build folder. It was easy. But Bcc32 is old and unsupported. Now I want to learn to use a more modern compiler and finding it to be much more cumbersome. Since I am not a professional programmer, I don't know all the "right ways" to compile. If you can point me towards a reference that explains how I can learn build cpp code efficiently (preferably, from command line), I would be most appreciative. – a1s2d3f4 Jul 14 '15 at 13:37

2 Answers2

10

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"

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
a1s2d3f4
  • 589
  • 4
  • 7
  • 18
1

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

Robert Altena
  • 787
  • 2
  • 11
  • 26