• Login
Community
  • Login

Run C++ without compiling

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
7 Posts 4 Posters 759 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J
    John Douglas
    last edited by Sep 9, 2024, 10:26 PM

    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?

    C 1 Reply Last reply Sep 9, 2024, 11:56 PM Reply Quote 0
    • C
      Coises @John Douglas
      last edited by Coises Sep 9, 2024, 11:57 PM Sep 9, 2024, 11:56 PM

      @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.

      1 Reply Last reply Reply Quote 3
      • R
        rdipardo
        last edited by Sep 10, 2024, 12:28 AM

        @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.

        1 Reply Last reply Reply Quote 2
        • R
          rdipardo
          last edited by Sep 10, 2024, 12:34 AM

          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

          1 Reply Last reply Reply Quote 2
          • R
            rdipardo
            last edited by Sep 10, 2024, 1:10 AM

            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)
            
            1 Reply Last reply Reply Quote 1
            • P
              PeterJones
              last edited by Sep 10, 2024, 1:06 PM

              @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.

              R 1 Reply Last reply Sep 10, 2024, 4:31 PM Reply Quote 1
              • R
                rdipardo @PeterJones
                last edited by Sep 10, 2024, 4:31 PM

                The directory will change automatically after clicking on NppExec’s “Follow $(CURRENT_DIRECTORY)” option (which I thought was enabled by default – sorry):

                Screenshot 2024-09-10 121533.png

                1 Reply Last reply Reply Quote 2
                5 out of 7
                • First post
                  5/7
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors