I'm usually using Visual Studio, but several things bother me when I just quickly want to test some code:
it has a rather long startup time
it always needs a project to execute/debug files
program output gets printed to the console, but the window simply closes when I don't insert a getchar() or a breakpoint in the program and thus I'm not seeing it.
I'm looking for a program which is suitable for a really, really quick programming in Windows. Such as, copying some code from an SO question, running it and seeing its output.
I don't think that console programs or g++ under CygWin are a good solution, because there it takes ages to cd into the right dir to save the file, I'm not used to editors such as Vim, and typing in the compiler commandline myself has always annoyed me etc.
So I guess what I'm looking for is a very lightweight free C/C++ IDE which is preconfigured to work with a free compiler (bonus points if it is even shipped with it.)
What can you recommend which adresses at least two items from the list above?
Is there maybe even a program which can execute/interpret C or C++ in an interactive commandline (like Python)?
I'm looking for a program which is suitable for a really, really quick
programming in Windows. Such as, copying some code from an SO question
and executing it and seeing it's output.
For quick-and-dirty experimental coding, I really like codepad.org. Not having to create a file is especially nice as it saves me from coming up with a suitable name and disk location. Be aware that it uses g++ 4.1.2 behind the scenes so some of the latest C++11 features aren't supported.
"really, really quick (and dirty, throw away?) programming "?
Compiler : VC++ command line - you already have it.
Editor: Notepad or somesuch
Compilation process: A .BAT file you write once
and supply a parameter with the name of the single source file.
Location: Set up some desktop shortcuts to a known directory for your
test code.
Use TCC : Tiny C Compiler
start a command prompt
cd wherever
notepad main.c
write code in notepad. save
back in the command prompt type tcc -run main.c
notice errors, go back to 4
Note that with -run parameter you're invoking tcc like an interpreter
Which compiler you use doesn’t really matter. I prefer G++ but cl.exe (from Visual Studio) works equally well.
In order to use the compiler quickly from the command line, either
include it into your PATH variable by setting it in the system settings, or
create a simple .cmd script which launches a console with the right paths included.
Visual Studio incidentally comes bundled with such a .cmd script which is linked in the Start Menu entry of Visual Studio. Personally, though, I prefer adjusting the PATH variable.
Then you can simply invoke the compiler from any directory in the command line. If you are too lazy to write the whole command line, create a script to do it for you. Or use Cygwin and (C)Make.
Two additional remarks:
Starting the project using the build configuration (Cntr+F5 (?)) leaves the console open after the program has run, without you having to include getch() calls or similar.
I highly recommend you learn an editor such as Emacs or Vim, unless you plan never to use any other platform than Windows, and even then. These editors are just tremendously powerful, and in some ways light-years beyond what the Visual Studio code editor offers.
But if you really don’t have the time, use a decent text editor such as Notepad++ instead.
Open Watcom is easy to install and use, it's fast and it's the closest compiler to MSVC++, although it's noticeably behind in features (especially in C++).
I don't use its IDE at all as I got used to doing most of the stuff in the console, but it's there and the debugger is there too.
Compiling one-filers is easy.
Compiling C code:
wcl386.exe /we /wx /q sourcefile.c
Compiling C++ code:
wcl386.exe /xs /we /wx /q sourcefile.cpp
On my machine, I have a "empty" project called "Test". When I want to test some random code on the internet, I simply put it into main.cpp in that project, and compile.
If you think MSVC takes too long to load, it should be possible to write a batch script that attempts to compile the project and puts the build log in a file. Then you can simply alter the existing main.cpp with notepad, double click the batch file, then pop open the build log or run the executable.
[Edit] I made a batch file to compile the entire solution. Turns out that requires loading visual studio. However, the batch file can compile/run a single cpp file easy enough.
My favorite IDE: http://www.codeblocks.org/
Here is a direct link to the download that includes the MinGW compiler: http://download2.berlios.de/codeblocks/codeblocks-10.05mingw-setup.exe
You're not gonna find any (good) C/C++ interpreters.
Once I used PSPad setting its "compiler" option for C++ files to a reasonable default (cl.exe in the correct directory, speed optimization, all warnings). Then it's just Ctrl+F9.
All of the above compiler recommendations are good. For an editor, I really like Notepad2
I know you didn't ask...
First off, your expectations are not reasonable. no program can guess what you want, over a range of input from the simplest to the most complex. If cd'ing into cygwin is too hard, and starting up visual studio is too time-consuming, you're pretty much toast. Sorry.
That said, you can edit code with notepad (which you can invoke from the command line as notepad foo.cpp). Notepad uses your mouse and the arrow keys on your pc so it's pretty intuitive.
you can use visual studio tools from the command line, without having to fiddle with project files.
Visual studio comes with a tool called nmake, the most basic usage of which is similar to linux make. If you have very simple input, nmake's default rules may be good enough to produce an executable. If not, you may be able to construct a makefile that will take any single simple file, say foo.cpp, and compile and link it to an executable called foo.exe. You'll still have to learn to use nmake, which some people think is easy, and others think is fiendishly difficult. Try nmake foo.cpp and see if the result is what you want.
Related
My current workflow when developing Apps or programs with Java or C/C++ is as follows:
I don't use any IDE like IntelliJ, Visual Studio, ...
Using linux or OS X, I use vim as code editor. When I build with a makefile or (when in Java) gradle, I :!make and wait for the compiler and linker to create the executable, which will be run automatically.
In case of compilation errors, the output of the compiler can get very long and the lines exceed the columns of the console. So everything gets messy, and sometimes takes too much time to find out, what the first error ist (often causing all following compile errors).
My question is, what is your workflow as a C++ developer? For example is there a way, to generate a nicely formatted local html file, that you can view / update in your browser window. Or other ideas?
Yes, I know. I could use Xcode or any other IDE. But I just don't want.
Compiling in vim with :!make instead of :make doesn't make any sense -- it's even one of the early features of vim. The former will expect us to have good eyes. The latter will display compilation errors into the quickfix window, which we can navigate. In other words, no need to use an auxiliary log file: we can navigate compilation errors even in (a coupled of) editors that run into a console.
I did expand on a related topic in https://stackoverflow.com/a/35702919/15934.
Regarding compilation, there are a few plugins that permits to compile in background. I've added this facility in build-tool-wrapper lately (it requires vim 7.4-1980 -- and it's still in a development branch at this time). This plugin also permits me to easily filter errors in the standard library with the venerable STLfilt, and to manage several build configurations (each in a separate directory).
i am using c++ in eclipse, a project which contains many header files , cpp files...etc when finally done, how does it actually get implemented in the real world once it is done? Does an .exe file get created ? Or how can users install the program on their computers?
Can you share your experience with me ?
Also can you tell me what IDE you use for C++ development ?
I tried to look through some documentation but could not find anything.
When you compile the code, it will output an executable file (.exe) that can then be run from a command line, double-clicked, or put into an installer. The executable files name will be .exe and placed in the output directory as specified in your project settings.
As mentioned, this can be bundled in an installer but that is very likely overkill and way beyond what you want. So long as you have used standard C/C++ libraries that come installed on a user's system, they can just invoke the program from a command line or simply double-click the executable. If your program doesn't have any interface and simply prints messages, then they person will want to run it from the command line. Finally, if you have used other libraries that you need to include with your program, then an installer may be what you need in order to make sure the end user has everything they need to run your program.
As far as IDE's go, I've used both Eclipse and Visual Studio. Visual Studio is better tailored to C/C++ development (this is assuming you are programming on a Windows machine) but has the downside of costing money if you don't get it through your employer or school. If you can get access to it through either of those channels, I would choose it over Eclipse. Eclipse will do what you want and is free, but Visual Studio might be a bit better. Also, if you are going to spend money anyway, I suggest looking a SlickEdit. I use this at work and really like it for C/C++ development.
How do I set my Visual studio 2008 compiler to GNU GCC. Can I also make it specific to projects? I didn't find any conclusive answer.
Thank you.
You can't use the compiler directly.
You can, however, invoke a makefile instead of using the built-in build system.
Example of configuration:
Install MinGW (I guess this step is already done), including mingw32-make
Create a makefile for mingw32-make called MinGWMakefile , with 3 targets: clean, build, and rebuild. This can be very tedious if you've never done that before.
Create a new configuration for your project
Go to configuration properties->general->configuration type, and select "makefile"
Go to configuration properties->NMake, and use these command lines:
Build Command Line: mingw32-make -f MinGWMakefile build
ReBuild Command Line: mingw32-make -f MinGWMakefile rebuild
Clean Command Line: mingw32-make -f MinGWMakefile clean
Enable "go to line" functionality on compiler messages:
You need to transform the output of gcc, from this:
filename:line:message
To this:
filename(line):message
I was using a custom C++ program to do that, but any regular expression tool will do the trick.
For best results, use GNU make, a Visual Studio makefile project, and a tool that you write yourself. Your makefile is a skeleton, that compiles files (use a variable for the files list), and your tool parses the .sln and .vcproj files to generate this file list. The makefile includes the result. Just needs a bit of glue and elbow grease -- you'll spend a day cursing make's unwillingness to do what you want, then you'll get it working. Once up and running this approach doesn't require too much maintenance.
You can keep your tool and makefile simple, just throwing all files in all projects into the mix and linking the result, using file patterns to decide what happens to each file, and putting all compiler options in the makefile. Or you can get more clever, pull #defines and include paths from the project, and maybe add in a Win32 project configuration that the makefile generator uses to properly handle custom build steps, excluded files, compiler options, and so on.
The easy approach should satisfy most, because it lets anybody add new files to the project just as they normally do, without having to concern themselves with the makefile, whilst making it hard for people to accidentally change settings that don't want changing.
I have previously described this approach (with a tiny bit more detail):
Good techniques to use Makefiles in VisualStudio?
(Once you have it set up, it works well, and in many respects it's actually more convenient than the usual VS approach, even before taking into account the fact you can now use other compilers.)
You may be able to make a custom makefile project to solve this for you.
Visual Studio's mainstream scenario is to be an IDE for MS developer tools. The more common ways to compile using GNU tools under Windows is MinGW or Cygwin.
Use external build system. (Makefile project).
As far as I know, there's no way to accomplish this. cl is more or less integrated with Visual Studio.
I guess if you were really desperate, you could try creating a pre-build step that invokes gcc and then doing something to stop the Visual Studio build from occurring.
I'am aware there has been a generic question about a "best IDE in C++" but I would like to stress I'm a new to C++ and programming in general. This means I have the needs of a student:
relatively easy and unbloated working environment
things just work, focus on the code
color coding to show the different language features (comments, etc)
not too unfriendly (not a simple editor, something to handle projects from start to finish)
cross-platform so not to be bound with specific system practices
I think the above are relatively reasonable demands for an educational IDE, perhaps excluding the last as such universal tool might not exist. Any ideas?
It depends on which world are you coming from to learn C++.
Do you have previous Java experience? - Use Eclipse CDT.
Have used .NET previously? - Go with Visual Studio C++ Express Edition (and then throw it away if you really need multiplatform IDE, not just code).
Are you an Unix guy? Use just a syntax-highlighting editor + Makefile. When you want to learn basics of the C++, the project should not be complicated and it is well invested time to learn how the C++ compiler is called with preprocessor options, etc.
Code::Blocks is free and really easy to install and use. I always recommend it to my students.
I've heard good things about Code::Blocks. Might be a bit complex, but you can close any unneeded panes, and it's cross-platform.
I would recommend Komodo Edit.
It functions as a great text editor that I've used on Ubuntu, Windows(XP/7) and OSX. It's big brother is a full blown IDE but KE still allows for projects and some great extensions. It's also free and open source. I found it easy to get started quickly with it and as your skills grow, it has the ability to keep up.
Edit to add a link to ActiveState's community site for Komodo Extensions. If you decide to try out KE, I'd suggest the RemoteDrive Tree (ssh,ftp,scp remote editing) and Source Tree as a start.
If you are using both windows and linux (as your comment indicates), I'd recommend Qt Creator. Qt is cross platform so your apps will work on linux, windows, and mac. Qt has excellent documentation, too, so it's very newbie friendly. Signals and Slots take a bit of getting used to, but IMO it's worth it.
Until the last point I would have said Microsoft Visual C++ Express Edition, which is free and fits your first 4 criteria. Cross platform you'd be looking at something like emacs or vim, neither of which are particularly friendly. On Windows I actually use Notepad++ for small C++ programs as it has good syntax highlighting and a (limited) intellisense.
I'd recommend Eclipse CDT as it does good code completion and it builds code on the fly, so you can see your errors immediately which is very good for a language studying.
Assuming Linux/Unix like system ...
I've found out that it's much easier and beneficial to go the other way round. Try using 'simple' editor like vim and for C++ just Makefiles to compile using gcc and linker.
I've started using that at uni and 5> years and couple of companies later it's still the easiest and most flexible option because you have quick access to all settings in one simple file.
Even when you switch to IDE later on you will know what to look for if things don't work because you will know the basics for example what are the steps to go from source file to object file and link to binary executable, how to handle libraries and so on. These things change between IDE's and are often complicated to trace and modify.
You can start with simple makefile and keep improving it over years. It's easy to copy it to your project directory and update file names - for C++ the compilation process will be fairly standard between projects.
I highly encourage you to consider this option. I've learned a lot doing it that way and you have a backup plan when you IDE just wouldn't work.
I keep one generic Makefile that compiles main.cpp into executable. To compile something quickly I just copy it into directory and make.
My current workflow is to open all files in project directory (flat file system) with vim (vim *.cpp *.hpp), edit, compile with :mak (or :mak -C .. debug) from within vim to invoke the Makefile stored in relevant directory, after compiling it'll jump to first warning/error, use :cn to go over errors, fix what's needed, open errors in separate window with :cope (close with :clo or unload file with :bd, jump between split windows with ctrl-w ctrl-w or ctrl-ww - hold ctrl and press w twice) ...
Vim has syntax highlighting millions of other features, I'm using tags (or ctags) to navigate code from within vim and so on.
Personally, it's my opinion that all C++ IDEs suck. When I write C or C++, I tend to use some sort of powerful programmer's text editor along with command line compilation. If I'm just messing around and have a couple source files, I'll just invoke gcc -g -o myprog *.c on the command line myself. If I have a more involved project, I'll just write a simple makefile. You could also look into gmakemake if you don't want to bother learning makefile syntax just to compile your programs.
On the Mac side, I have always been a fan of both BBEdit and TextMate, but much more so of the latter, especially given its lesser price tag and more modern feel. Both have project organization features.
On Windows, I'd stick with either e (which is basically a port of TextMate to Windows) or Notepad++. The downside of Notepad++ is that it doesn't have any project organization features, whereas e does. You could also look at SciTE, but like Notepad++, it has no project org features.
As for Linux, I'm personally unsure. I'd stick with other people's answers covering that platform for recommendations there.
Is there any way to build/run small C++ programs, in Visual Studio without creating projects?
For example, if I have a file hello.cpp, can I compile it to hello.exe without a project?
GMan's idea of having a 'sandbox' project is a good one, as it allows for easily trying out multi-file tests. I call mine "cppTest".
However, if you just want to be able to compile whatever C or C++ file you happen to have open, just create a simple "External Tool". Actually, it's not as simple as it probably should be.
First, create a batch file that will set up the compiler environment and run the compiler. Something like the following:
#rem - runcl.cmd
#rem a batch file to drive simple VC9 compiles
#rem
#echo off
set LIBRARIES=kernel32.lib user32.lib advapi32.lib shlwapi.lib oleaut32.lib
set WIN32_WINNT=0x0500
call "%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"
echo Visual C/C++ 2008 (VC 9.0) Compile...
set CC="%ProgramFiles%\Microsoft Visual Studio 9.0\VC\bin\cl.exe" /Zi /EHsc -D_WIN32_WINNT=%WIN32_WINNT% %1 /link /incremental:no %LIBRARIES%
echo %CC%
%CC%
In the "Tools/External Tools..." dialog, add a new item and fill in the following fields:
Title: &Compile File
Command: c:\path\to\runcl.cmd
Arguments: $(ItemPath)
Initial Directory: $(ItemDir)
check the "Use Output Window" box
Now you can use the "Compile File" item in the Tools menu to compile whatever is the currently open file. You can even double click on the errors in the output window to take you to the lines with errors.
There are some limitations with this some of which you can fix by fancying up the batch file or maybe with a Visual Studio macro (I'm not very familiar with VS macros).
if you haven't saved the file, the compile will run against the most recent save. There's no option in the External Tools configuration to force a save.
if you run the command and there's not a C or C++ file active, the batch file will fall over
there are probably quite a few other areas where the batch file will get confused
The nice thing about a batch file like this is that you can also use it to help integrate the compiler into various editors that let you call external tools, like UltraEdit, Zeus Editor, EditPad Pro, PSPad, Programmer's Notepad, etc. etc.
If you like, I've posted a batch file that I use to integrate several compilers into editors like the above. This batch file handles several compilers including various MSVC compilers from version 6 through version 9, Digital Mars, MinGW and Comeau compilers (the compiler to use is selected by an additional parameter). The batch file is pretty convoluted (unfortunately, that's the nature of Windows batch files that have any kind of complexity). But I find it makes running these things from various editors pretty simple. I can quickly hit a few keys that I've assigned to the compilers to compile a single file against 5 different compilers so I can test for compatibility easily.
I make no promises about it other than I find it useful for my own purposes - if you do too, great. Otherwise, don't use it...
https://gist.github.com/mburr/3308168
Within the actual IDE, I don't think it's possible to run a small program, you have to use the command line like Matt suggested.
The solution I have for this problem, is that I have one project on my computers called "sandbox", which just has a main.cpp, and it's where I can mess around.
It let's me try things out here and there, but I never have to keep starting a new project.
One way to do this is to build a generic project such as sandbox, test, or even Hello World and then add and remove source files to change what you want to do. You can even remove the old source file and then add new to start over fresh. This is quick and easy while making it possible to return programs that are built.
If you have a hello.cpp file and would like it to compile into a hello.exe file without creating a project in code::blocks or visual studio you could look into: https://courses.cs.washington.edu/courses/cse373/99au/unix/g++.html
A guide on how to install g++ via MinGW on windows: http://www.codebind.com/cprogramming/install-mingw-windows-10-gcc/
Then you would be able to compile a single hello.cpp file by opening your command prompt, navigating to your file (the hello.cpp file) wherever you have placed it and run the command g++ -o hello hello.cpp which should result in a file with the name "hello.exe" in the same location as your hello.cpp.
Note that this is not part of visual studio but is an easy way to just compile a single .cpp file if you would like to keep it simple.