0

I just switched to ubuntu and I wanted to setup notepad++ for CPP.

So I used the NppExec plugin to compile within notepad++,

My script was :

npp_save
g++ "$(FULL_CURRENT_PATH)" -o "$(CURRENT_DIRECTORY)\$(NAME_PART)obj"
./"$(NAME_PART)obj"

Here the "obj" I used is to just save the file with an "obj" keyword nothing else.

The last line ./"$(NAME_PART)obj" is to run the program.

But it looks not working in ubuntu, it produces this error:

NPP_SAVE: Z:\home\username\cpp\test.cpp
g++ "Z:\home\username\cpp\test.cpp" -o "Z:\home\username\cpp\testobj"
; about to start a child process: "g++ "Z:\home\username\cpp\test.cpp" -o "Z:\home\username\cpp\testobj"
CreatProcess() failed with error code 2:
File not found.

./"testobj"
; about to start a child process: "./"testobj""
CreatProcess() failed with error code 2:
File not found.

I have investigated some of what I think is the problem, so I think is the usage of / and \ in changing the directory.

I don't know how to fix that, so I can not be sure.

Any ideas? :) I am using vim btw in the same machine and it is working perfectly.

Luc Hermitte
  • 31,979
  • 7
  • 69
  • 83
diifuso
  • 66
  • 8
  • You may try to remove the `"`. Useless in linux, no white spaces in file names – Damien Dec 18 '20 at 07:13
  • Do you have g++ somewhere on your path? – Alan Birtles Dec 18 '20 at 07:22
  • @Damien you absolutely can have spaces in file names on Linux and can wrap them in quotes to prevent errors – Alan Birtles Dec 18 '20 at 07:23
  • @AlanBirtles I have always read that it was not recommended to have spaces in linux file names. It doesn't mean effectively that it is not allowed at all. I have exchanged files between Linux and Windows for decades, and after unsolved problems I decided a long time ago to avoid spaces. I even had problems with that in Windows! Maybe recent linux systems are more resilient. – Damien Dec 18 '20 at 07:56
  • @Damien They cause no more or less problems than they do on Windows – Alan Birtles Dec 18 '20 at 07:59
  • @Damien, I tried it without `"` but it is not the case. The same problem occurs with or without the `"`. – diifuso Dec 18 '20 at 10:19
  • @AlanBirtles, yes, g++ is pre-installed in my ubuntu version. I am using Vim currently and it is compiling very well. – diifuso Dec 18 '20 at 10:21
  • Did you try to run the `g++ ...` same command line in a terminal, in same directory? – Damien Dec 18 '20 at 10:23
  • @Damien, yes I did, and it is compiling. The problem is with the script itself, I mean the script of the NppExec when executing. – diifuso Dec 18 '20 at 10:32
  • how are you running notepad++? are you using wine? if so see https://stackoverflow.com/questions/7249791/wine-path-through-command-line-and-not-persistent – Alan Birtles Dec 18 '20 at 10:50

1 Answers1

0

In theory it might be possible (see below), in practice it is rather convoluted and works only for simple compiles (like single file hello world type).

I would suggest you try a linux program, e.g.

  • an editor like
    • scite (same editing engine as notepad++) or
    • kate
  • or a real IDE like
    • kdeveloper or
    • qtcreator.

The problems with Notepad++ inside wine and g++ outside wine (from the linux install ) are this:

  • notepad++ inside wine under linux is still a windows program
  • NppExec can only do, what a cmd inside wine can do.
  • starting g++ directly inside cmd is an error due to g++ being a linux binary and not a windows binary
    • that is your CreatProcess() failed with error code 2, it means: you are trying to execute a linux program inside wine.
    • That does not work! (At least not so easy.)
    • Though you can start linux program inside cmd inside wine using start /unix ...
  • started this way, g++ wants linux paths and NppExec through its variables will provide only windows paths (whatever wine has set up as drives like Z:\home\username\src\hello.cpp)
    • though you can convert wine paths to linux paths via the winepath -u command.
  • g++ started through 'start /unix ... ' inside a cmd inside wine has no proper terminal to report errors to you
    • though you can start an xterm for g++ and have g++ reports its messages to the xterm
  • the downside is that g++ will report errors using the linux paths in the xterm, so you cannot double click on an error message an get to the corresponding filename and line.

You get the idea: its complicated not comfortable.

What worked for me for a helloword.cpp was this NppExec script:

NPP_SAVE
npp_run cmd /c start /unix /usr/bin/xterm -e "/usr/bin/winepath -u '$(FULL_CURRENT_PATH)' | xargs g++ -o /tmp/a.out && /tmp/a.out ; echo 'Press return'; read"

The second line

  • uses an xterm,
  • let winepath convert the Z:\home\... path to /home/... and
  • have that send to g++ for compilation using /tmp/a.out as binary
  • if compile is successfull, /tmp/a.out is executed
  • the echo and read are for keeping the xterm open so that you can read the output.

If you really want to use Notepad++ inside wine, one option might be using Gnu Make outside of wine and have NppExec run make all or make run similar to the g++ in my script example. That would work for more complicated compiles.

Lars Fischer
  • 9,135
  • 3
  • 26
  • 35