如何在Notepad ++中编译/执行C ++代码 [英] How to compile/execute C++ code from within Notepad++

查看:305
本文介绍了如何在Notepad ++中编译/执行C ++代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 http://daleswanson.blogspot.com/2012/07/how-to-compile-c-code-in-notepad-with.html 并决定尝试该方法,以便我可以继续用Notepad ++,并且编译/运行周期更短.

I was reading http://daleswanson.blogspot.com/2012/07/how-to-compile-c-code-in-notepad-with.html and decided to try that, so that I can continue to write code in Notepad++ and have a shorter compile/run cycle.

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

When I tried to enter compilation/run code into NppExec, it's not working. The code I have now is:

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

那是基于我给出的第一个链接:

That was based off the first link I gave:

npp_save
cd "$(CURRENT_DIRECTORY)"
g++ "$(FILE_NAME)" -o $(NAME_PART) -march=native -O3
NPP_RUN $(NAME_PART)

Notepad ++在其控制台中为我提供了以下信息:

Notepad++ gives me the following information in its Console:

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

在其他页面上,好像我只需要粘贴该代码,所有大写字母不是要替换的,而是变量.所以我使用了这段代码:

From other pages it seemed as though I just needed to paste that code in, that the all caps words aren't meant to be replaced but are variables. So I used this code:

npp_save
cd "$(CURRENT_DIRECTORY)"
g++ "$(FILE_NAME)" -o $(NAME_PART) -march=native -O3
NPP_RUN $(NAME_PART)

在记事本++控制台中提供了以下内容:

Which gave the following in the Notepad++ Console:

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

这是我要做的事情:

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

I downloaded mingw-get-setup.exe from http://sourceforge.net/projects/mingw/files/ which installed the MinGW Installation Manager. I then used it to install the mingw32-gcc-++ package, as well as the mingw32-libz.dll and mingw32-libz.dev packages

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

In Notepad++ I used the Plugin Manager to install the NppExec plugin.

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

I can get my code to run by first manually compiling it in a command window. Notepad++ complains that it's missing a library, so I'm using the following flags when I compile: g++ test.cpp -static-libgcc -static-libstdc++

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

If I hit F5 in Notepad++ (or click Run in the Run menu), I can choose the a.exe file that's created from my command line compilation, and it will popup a command window and run that code, so that works fine.

但是当我尝试自动执行编译/运行时,似乎由于某些原因,我的更改目录命令在NppExec中无法正常工作.

But it seems as though my change directory command isn't working for some reason in NppExec when I try to automate the compile/run.

我发现还有其他一些stackoverflow帖子,它们解决了类似的问题,但似乎不适用于我.我没有任何要点,所以我无法回复其中任何一个:

Here are some other stackoverflow posts I've found that address similar problems, but which don't seem applicable to me. I don't have any points, so I can't reply to any of them:

  • 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窗口中放置以下内容:

Well, it looks like the first post I linked to has a partial solution -- it looked like (despite the mention of c files in the post name) that it was summarizing how to compile perl scripts. It said to put the following in the NppExec window:

NPP_SAVE
CD $(CURRENT_DIRECTORY)
C:\MinGW32\bin\gcc.exe -g "$(FILE_NAME)"
a.exe

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

It just had "a" on the final line, but that's the same as "a.exe" and it's more human readable this way. That being said, this is not a full solution. This just runs the file in Notepad++'s internal console, at the bottom of the screen and I'd like it to popup a window, as would happen if I used Notepad++'s F5 to run my compiled program from its directoy.

推荐答案

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

I've got a working code (that I edited a bit) from here:
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

以这种形式,它在源文件旁边编译二进制文件.如果将最后一行更改为此:

In this form it compiles the binary next to the source file. If you change the last line to this:

cmd /c "$(CURRENT_DIRECTORY)\$(NAME_PART).exe"

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

then the program runs in the NppExec console with running cmd.exe.

这篇关于如何在Notepad ++中编译/执行C ++代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆