Microsoft Visual C++, compiling small source codes without project file
Asked Answered
A

4

16

Well, I've been using Dev-C++ for a while for learning the language [c++], and some stuff wouldn't work properly, like global and local variables. Then I decided to download Microsoft Visual C++ to see how it compared, and it was absolutely great; especially with its aesthetics. One thing that has bothered me, though, is that since I need to make lots of small source files to test out things I've learned, I have to make a large project file each and every time, which take up ~18mb of space. I have tried to just make a source C++ file, but it never works since the compile and run buttons don't highlight without a project file, and pressing f5 yields no result as well. But with Dev-C++, I could just open it up, control+n, and write the program quickly, compile and it'd show up, no need for a project file. So is there a way to to compile single source files in Microsoft Visual C++ without needing to make a project file to include it in?

Aplacental answered 9/12, 2010 at 0:25 Comment(3)
Not easily. The IDEs are probably a bit heavy for your needs. For single-source files, you can even just use a syntax-highlighting indenting code editor like Notepad++ and a command-line compiler. The IDEs are probably too much for this, until you get into multi-source file projects.Kirtley
possible duplicate of Running small C++ programs in Visual Studio without creating projectsAmbivalence
Whoops, didn't notice that, Michael. Thanks for the heads up, it seems to answer my question.Aplacental
S
8

I typically make one project for temporary work and just re-use it. If you have a really desperate need to keep around your learning files, then just make one project, add new source files, and exclude all the old ones from the build. There's no need to make a new project for every temporary or learning project.

Snowmobile answered 9/12, 2010 at 0:30 Comment(0)
S
22

For simple program, you can easily compile from command line,

Star menu->Visual Studio->Visual Studio Tools->Command Line

cd c:\..\your program path
cl.exe test.cpp
Spiceberry answered 9/12, 2010 at 0:35 Comment(0)
S
8

I typically make one project for temporary work and just re-use it. If you have a really desperate need to keep around your learning files, then just make one project, add new source files, and exclude all the old ones from the build. There's no need to make a new project for every temporary or learning project.

Snowmobile answered 9/12, 2010 at 0:30 Comment(0)
C
2

You can execute the compiler from the command line. First you will need to open a command prompt will all the VC++ environment variables set. Then you just invoke "cl" with the options you want.

If you want to stay within the IDE, then you can set up an "External Tool" to compile it for you:

  1. From Visual Studio select Tools\External Tools
  2. Click "Add" on the dialog box.
  3. Pick a suitable name like "Compile"
  4. For "Command" choose cl.exe
  5. Foor "Arguments" enter $(ItemPath)
  6. Check "use Output Window" so that the compiler output is sent to the output window.

Now, to use this, you must invoke Visual Studio with the correct environment variables set. One way is to launch a Visual Studio Command Prompt and then enter devenv.exe. Then open the file you want to compile and select the new tool under the Tools menu.

Confessor answered 9/12, 2010 at 0:36 Comment(1)
Thanks for the informative answer, I think I'll try this later on.Aplacental
S
0

Microsoft has a web page walkthrough for compiling at the command line. The prerequisites are:

To complete this walkthrough, you must have installed either Visual Studio and the optional Desktop development with C++ workload, or the command-line Build Tools for Visual Studio.

Stenson answered 14/7 at 23:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.