8

I want to compile a C++ source file without making a project in visual studio 2017 without making a project like we do in some code editors, how can I do that. Can anyone please tell?

Here is an example, in sublime text, I create a code and then compile it by ctrl + b.In a similar manner, I want to do that in visual studio 2017.

Juli15
  • 411
  • 7
  • 17
WildFire
  • 79
  • 1
  • 9
  • 3
    [Invoke the `cl.exe` compiler frontend program directly from the command line?](https://msdn.microsoft.com/en-us/library/f35ctcxw.aspx) – Some programmer dude May 18 '18 at 07:51
  • Not possible with the IDE (can be done from the command line). My workaround is to have a permanent "playpen" project into which I can drop test files or copy-paste code. – Richard Critten May 18 '18 at 08:05
  • Is this a possible duplicate of https://stackoverflow.com/questions/880803/running-small-c-programs-in-visual-studio-without-creating-projects/52800795#52800795? – darclander Nov 22 '18 at 11:53
  • Possible duplicate of [Run cl.exe from cmd](https://stackoverflow.com/q/84404/608639) – jww Nov 23 '18 at 17:37

3 Answers3

7

You can open a folder and start coding in visual studio without creating a project or solution file.

They call it the Open Folder feature.

Visual Studio 2017 introduces the "Open Folder" feature, which enables you to open a folder of source files and immediately start coding with support for IntelliSense, browsing, refactoring, debugging, and so on. No .sln or .vcxproj files are loaded...

from the main menu select File | Open | Folder or press Ctrl + Shift + Alt + O.

The easiest way I found from there is to right click in the "Solution Explorer" area and select "Open Developer Command Prompt". From there you can use cl to compile your program however you see fit.

Community
  • 1
  • 1
Increasingly Idiotic
  • 5,700
  • 5
  • 35
  • 73
  • I think that Developer Command Prompt method was easier , i left VSCODE because of the '.json' configuration.Thank you. – WildFire May 18 '18 at 08:37
6

You can open "Developer Command Prompt for VS2017" at the start menu and use cl.exe to compile your source code.

E.g. c++ source file name: test.cpp
type "cl test.cpp"
Then, it will generate "test.obj" and "test.exe" if no bugs found.

You can type "cl" for simple usage and "cl /?" for complete help.

Patrick
  • 77
  • 2
  • well `cl /nologo /W3 /Ox /Tc yourfile.c` (you can also create individual directories for `obj` and `exe` files to keep your source dir clean and add `/Foname1/` and `/Fename2/` to put `.obj` files in a directory called `name1` and your executables in `name2`) It works the same to C++, just use `/Tp` for the file type. – David C. Rankin May 18 '18 at 08:34
1

If you wish to get away from the IDEs I would recommend looking up MinGW for compiling in the command prompt. If you are running Ubuntu or something similar I believe you can compile in bash without further extensions.

For MinGW http://www.mingw.org/wiki/mingw_for_first_time_users_howto

I believe you compile in the same way in ubuntu if not I believe you can find some sources for that aswell.

Pros about compiling in the terminal is mostly that you do not have to setup a complete project but you can make your own personal little setup. Of course an IDE is a simple way to start but compiling in the terminal also helps you understand what is actually happening instead of just pressing "Debug".

darclander
  • 1,526
  • 1
  • 13
  • 35