Trying to add a C compiler to the "run" options
-
I’ve installed the MinGW GCC Compiler and I’m trying to follow the instructions here so that I can push Ctrl+F9 to compile and then Ctrl+F5 to execute my code. However, everytime I run:
gcc -o “$(NAME_PART)” “$(FULL_CURRENT_PATH)”
I see my command prompt appear very quickly and disappear but my code file is never compiled.
If I navigate to the file in command prompt and run it manually it does compile so I’m not really sure what I’m doing wrong - Is the article out of date now? Do these variables no longer work in Notepad++?
I even tried adding “> output.txt” to the end to see what it’s actually doing in the command prompt window but can’t get that to work either. This is all a bit new for me.
Please help? Thanks in advance!
-
You are not the noob you make yourself out to be. I think you are on the right track, and are almost there.
Try:
cmd /c echo gcc -o "$(NAME_PART)" "$(FULL_CURRENT_PATH)" && pause
from the Run (menu) -> The Program to Run field. This should show you how the special $(XXX) are being replaced for you. Adjust as necessary for what you need.
You may also may want to refer here: http://docs.notepad-plus-plus.org/index.php/Defining_User_Commands
-
Here’s a little The Program to Run entry that will show the current values for most of the special $(XXX) values for your current file/setup:
cmd /c echo FCP=$(FULL_CURRENT_PATH) CD=$(CURRENT_DIRECTORY) FN=$(FILE_NAME) NP=$(NAME_PART) EP=$(EXT_PART) ND=$(NPP_DIRECTORY) CW=$(CURRENT_WORD) CL=$(CURRENT_LINE) CC=$(CURRENT_COLUMN) && pause
Unfortunately if you spell it out fully (e.g., use
FULL_CURRENT_PATH=$(FULL_CURRENT_PATH)
), then it doesn’t work…probably too long of a command…Interestingly, the line and column info is zero-based, making it less than somewhat less than useful.
-
@Scott-Sumner said:
probably too long of a command
So some testing shows that for me the longest user text I can put in the The Program to Run box and have it work is 259 characters. I can put more characters in, but it will truncate to 259 before running. If I enter a too-long entry and then go back in like I want to run it again, the truncated version is what was remembered.
Here’s what I tried (success, 259):
cmd /c echo aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjjkkkkkkkkkkllllllllllmmmmmmmmmmnnnnnnnnnnooooooooooppppppppppqqqqqqqqqqrrrrrrrrrrssssssssssttttttttttuuuuuuuuuuvvvvvvvvvvwwwwwwwwwwxxxxxxxx && pause
And failure (260):
cmd /c echo aaaaaaaaaabbbbbbbbbbccccccccccddddddddddeeeeeeeeeeffffffffffgggggggggghhhhhhhhhhiiiiiiiiiijjjjjjjjjjkkkkkkkkkkllllllllllmmmmmmmmmmnnnnnnnnnnooooooooooppppppppppqqqqqqqqqqrrrrrrrrrrssssssssssttttttttttuuuuuuuuuuvvvvvvvvvvwwwwwwwwwwxxxxxxxxx && pause
Note that this is only user entered text; if you include one or more of the special $(XXX) substitution values, the expansion can create text that is longer than 259 and that will still work.
-
Hi, @scott-sumner, and All,
Like you, Scott, I noticed that, after the cmd command and its trailing space, only the first 255 characters, typed in The program to run box, are taken in account, whereas you can easily write up to
2048
( and probably more, but I haven’t test it, yet ! ) in a native DOS windows !Here is, below, an other way to get all the
$(xxxxx)
variables. Just note that I’m using the/k
parameter, which prevents me from adding, at the end, thepause
command. Of course, you need to close the DOS window, manually !cmd /k echo Pth = $(FULL_CURRENT_PATH)&echo Dir = $(CURRENT_DIRECTORY)&echo N++ = $(NPP_DIRECTORY) --&echo Fil = $(FILE_NAME)&echo Nme = $(NAME_PART)&echo Ext = $(EXT_PART) --&echo Wrd = $(CURRENT_WORD)&echo Lin = $(CURRENT_LINE)&echo Col = $(CURRENT_COLUMN)
Cheers,
guy038
-
Of course, one could take less of a “brute force” method than I initially did…and check the source code to arrive at the same 259 character limit:
RunDlg.cpp:
INT_PTR CALLBACK RunDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { //...snip... case WM_COMMAND : { switch (wParam) { //...snip... case IDOK : { TCHAR cmd[MAX_PATH]; ::GetDlgItemText(_hSelf, IDC_COMBO_RUN_PATH, cmd, MAX_PATH);
WinDef.h:
#define MAX_PATH 260
The GetDlgItemText function docs discuss the one-byte null terminator for C-style strings (thus 259+1=260) and the truncation that occurs when the limit is exceeded, so all is explained. :-D