How to compile and run C files from within Notepad++ using NppExec plugin?

前端 未结 10 1435
北荒
北荒 2020-11-30 00:45

How can I configure the NppExec plugin for Notepad++?

I would like NppExec to compile my C files, run them, and show their output, all within Notepad++.

10条回答
  •  失恋的感觉
    2020-11-30 01:13

    You can actually compile and run C code even without the use of nppexec plugins. If you use MingW32 C compiler, use g++ for C++ language and gcc for C language.

    Paste this code into the notepad++ run section

    cmd /k cd $(CURRENT_DIRECTORY) && gcc $(FILE_NAME) -o $(NAME_PART).exe  && $(NAME_PART).exe && pause
    

    It will compile your C code into exe and run it immediately. It's like a build and run feature in CodeBlock. All these are done with some cmd knowledge.

    Explanation:

    1. cmd /k is used for testing.
      • Full explanation @ http://ss64.com/nt/cmd.html
    2. cd $(CURRENT_DIRECTORY)
      • change directory to where file is located
    3. && operators
      • to chain your commands in a single line
    4. gcc $(FILE_NAME)
      • use GCC to compile File with its file extension.
    5. -o $(NAME_PART).exe
      • this flag allow you to choose your output filename. $(NAME_PART) does not include file extension.
    6. $(NAME_PART).exe
      • this alone runs your program
    7. pause
      • this command is used to keep your console open after file has been executed.

    For more info on notepad++ commands, go to

    http://docs.notepad-plus-plus.org/index.php/External_Programs

提交回复
热议问题