Run C++ without compiling
-
Can I run C++ without compiling? Every time I run some code I end up with an exe file.
I have set up MinGW-w64 to run from the Macro Menu and it works ok, except that there is no out put displayed in the consol. How can I display the results of my code in the consol?
-
@John-Douglas said in Run C++ without compiling:
Can I run C++ without compiling? Every time I run some code I end up with an exe file.
I have set up MinGW-w64 to run from the Macro Menu and it works ok, except that there is no out put displayed in the consol. How can I display the results of my code in the consol?
What you want would be an interpreter, rather than a compiler.
I looked a bit, but I could not find any C++ interpreters that run on Windows and have binaries already built and ready to install. You can search and see if you can make out anything that’s within your ability to set up. It all looked absurdly complicated to me.
My advice is that unless you have a really good reason for doing what you’re trying to do, either scrap the idea of running your code from Notepad++ and just use MS Visual Studio to write, compile, execute and debug C++ code; or else forget about C++ and use a language that’s designed to be interpreted, like Python.
-
@John-Douglas said in Run C++ without compiling:
How can I display the results of my code in the consol?
Dev-C++ has a “Build and Run” command, with output going directly to a built-in console window. I believe Eclipse can do something similar with the CDT plugin installed.
-
P.S. You can skip the Embarcadero website and download Dev-C++ from GitHub without signing up for anything: https://github.com/Embarcadero/Dev-Cpp/releases
-
P.P.S Not to leave out Notepad++, you could also just install the NppExec plugin.
Assuming your MinGW toolchain is in the
PATH
, just open the NppExec console and run this:cmd /c g++ $(FULL_CURRENT_PATH) -o $(NAME_PART) & .\$(NAME_PART)
-
@rdipardo said,
cmd /c g++ $(FULL_CURRENT_PATH) -o $(NAME_PART) & .\$(NAME_PART)
That assumes that NppExec’s current working directory is the same as the active file. And that the active file’s full current path has no spaces. Both are dangerous assumptions, in my opinion.
I would use Plugins > NppExec > Execute NppExec Script…, and create (and save) the script:
npp_save cd "$(CURRENT_DIRECTORY)" g++ "$(FILE_NAME)" -o "$(NAME_PART)" cmd.exe /c "$(NAME_PART)"
… this will save the active file (to make sure you’re always running the most recent), change into the active file’s directory (because we cannot know what directory NppExec currently thinks of as “active”, so if you’ve run other scripts recently, it might not be where you think it is), build the executable out of it, and then run that executable in the NppExec console panel inside Notepad++. By using the quotes surrounding the directory and file names, it makes sure that it will handle spaces in the path or filename correctly.
If it were something I did often, I’d also use NppExec’s Advanced Options… dialog to put that script into the menu, and then (after restarting Notepad++) use Settings > Shortcut Mapper to assign a keyboard shortcut.
-
The directory will change automatically after clicking on NppExec’s “Follow $(CURRENT_DIRECTORY)” option (which I thought was enabled by default – sorry):