notepad++ - 如何在Notepad++中编译/执行C++代码

标签 notepad++ nppexec

我正在阅读http://daleswanson.blogspot.com/2012/07/how-to-compile-c-code-in-notepad-with.html并决定尝试这样做,以便我可以继续在Notepad++中编写代码并缩短编译/运行周期。

当我尝试在NppExec中输入编译/运行代码时,它不起作用。我现在拥有的代码是:

npp_save
cd "$(C:\Users\Bart\Desktop\new delete me)"
g++ "$(test.cpp)" -o $(testme.exe) -march=native -O3
NPP_RUN $(testme.exe)

那是基于我给的第一个链接:
npp_save
cd "$(CURRENT_DIRECTORY)"
g++ "$(FILE_NAME)" -o $(NAME_PART) -march=native -O3
NPP_RUN $(NAME_PART)

Notepad++在其控制台中为我提供了以下信息:
NPP_SAVE: C:\Users\Bart\Desktop\new delete me\test.cpp
CD: 
Current directory: C:\Program Files (x86)\Notepad++
g++ "" -o  -march=native -O3
CreateProcess() failed with error code 2:
The system cannot find the file specified.

NPP_RUN:
- empty command

在其他页面上,好像我只需要粘贴该代码,所有大写字母不是要替换的而是变量。所以我用了这段代码:
npp_save
cd "$(CURRENT_DIRECTORY)"
g++ "$(FILE_NAME)" -o $(NAME_PART) -march=native -O3
NPP_RUN $(NAME_PART)

在Notepad++控制台中提供了以下内容:
NPP_SAVE: C:\Users\Bart\Desktop\new delete me\test.cpp
CD: C:\Users\Bart\Desktop\new delete me
Current directory: C:\Users\Bart\Desktop\new delete me
g++ "test.cpp" -o test -march=native -O3
CreateProcess() failed with error code 2:
The system cannot find the file specified.

NPP_RUN: test
- the specified file was not found

这是我要做的设置工作:

我从安装了MinGW Installation Manager的http://sourceforge.net/projects/mingw/files/下载了mingw-get-setup.exe。然后,我用它来安装mingw32-gcc-++软件包以及mingw32-libz.dll和mingw32-libz.dev软件包

在Notepad++中,我使用了插件管理器来安装NppExec插件。

通过首先在命令窗口中手动进行编译,可以使我的代码运行。 Notepad++提示它缺少一个库,因此我在编译时使用以下标志:
g++ test.cpp -static-libgcc -static-libstdc++

如果我在Notepad++中按F5键(或在“运行”菜单中单击“运行”),则可以选择从命令行编译创建的a.exe文件,它将弹出一个命令窗口并运行该代码,因此效果很好。

但是,当我尝试自动执行编译/运行时,似乎由于某些原因,我的更改目录命令在NppExec中不起作用。

这是我发现的其他一些stackoverflow帖子,它们解决了类似的问题,但似乎不适用于我。我没有任何要点,所以我无法回复其中任何一个:
  • How to compile and run C files from within Notepad++ using NppExec plugin?
  • Final Setup of gcc in Notepad++ [using nppexec]
  • Notepad++, NppExec, CreateProcess() failed with error code 2, Windows 8.1

  • 好吧,看来我链接到的第一篇文章有​​一个部分解决方案-看起来(尽管在文章名称中提到了c文件)它正在总结如何编译perl脚本。它说将以下内容放在NppExec窗口中:
    NPP_SAVE
    CD $(CURRENT_DIRECTORY)
    C:\MinGW32\bin\gcc.exe -g "$(FILE_NAME)"
    a.exe
    

    它在最后一行仅带有“a”,但这与“a.exe”相同,并且这种方式更容易被人阅读。话虽如此,这不是一个完整的解决方案。这只是在屏幕底部的Notepad++内部控制台中运行文件,我希望它弹出一个窗口,就像我使用Notepad++ F5从其Directoy运行编译程序时那样。

    最佳答案

    我从这里得到了一个工作代码(我做了一点编辑):
    http://windowsbro.blogspot.hu/2012/10/compile-with-notepad-any-language.html

    npp_save
    g++ "$(FULL_CURRENT_PATH)" -o "$(CURRENT_DIRECTORY)\$(NAME_PART).exe"
    npp_run $(CURRENT_DIRECTORY)\$(NAME_PART).exe
    

    它以这种形式编译源文件旁边的二进制文件。如果将最后一行更改为此:
    cmd /c "$(CURRENT_DIRECTORY)\$(NAME_PART).exe"
    

    然后该程序在NppExec控制台中以cmd.exe运行。

    关于notepad++ - 如何在Notepad++中编译/执行C++代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27980134/

    相关文章:

    python - Windows 中 Python 的缓冲输出与非缓冲输出

    bash - 使用 NppExec(和 Cygwin)在 Notepad++ 中的 Windows 上运行 bash shell 脚本

    在 Notepad++ 中配置 NppExec 以进行 C 编程

    regex - 删除每行开头的行号

    regex - 为什么这个正则表达式前缀不起作用?

    JavaScript 或 Notepad++ 正则表达式向任意文本添加千位分隔符

    Notepad++ PL/SQL 函数列表

    java - 使用Notepad++编译多个java类

    perl - 让 perldoc 在 notepad++ 和 NppExec 中工作