Notepad++, NppExec, CreateProcess() failed with error code 2, Windows 8.1 - c++

I'm new to Notepad++ and C++ programming language. I couldn't figure out what has gone wrong, albeit, it might look simple to resolved to many.
Tried to search for solution, but to no avail.
While trying to config the application for C++ compiler on Windows 8.1, I encountered the below message.
NPP_SAVE: C:\Users\rolle_000\Desktop\HelloWorld.cpp
CD: C:\Users\rolle_000\Desktop
Current directory: C:\Users\rolle_000\Desktop
Compiled.exe -c -w "HelloWorld.cpp"
CreateProcess() failed with error code 2:
The system cannot find the file specified.
================ READY ================
The C++ basic code, simple to testing only.
// A hello world program in C++
#include<iostream>
using namespace std;
int main()
{
cout << "Hello World!";
return 0;
}
The NppExec script taken from
How to compile and run C files from within Notepad++ using NppExec plugin?
Below embedded mine, script hasn't change much.
NPP_SAVE
CD $(CURRENT_DIRECTORY)
Compiled.exe -c -w "$(FILE_NAME)"
Pls advice, thank you.

You're trying to execute a
Compiled.exe
which indeed doesn't exist (yet) instead of the
perl.exe -c -w "$(FILE_NAME)"
perl.exe is the perl's executable and is supposed to be used with a perl's program. To compile C++ programs you will need to use a C++ compiler.
Now: this all boils down to the compiler you want to use... which one are you going to use? MSVC (Microsoft Visual Studio) ? Bloodshed dev-cpp?
Example: if you have MSVC2010 installed you might use:
Execute Start->All Programs->Microsoft Visual Studio 2010->Visual Studio Tools->Visual Studio Command Prompt (2010)
Digit cl (yourFileName).cpp
You're done, yourFileName.exe should now exist
So the above would have to be rewritten as:
cl.exe "$(FILE_NAME)"
after making sure the path to cl.exe is correctly available.

Related

i don't know what is wrong with vs code in running cpp

i just started to code in cpp and nothing is working idk if i didn't install the gcc properly or what but i already set the path of the bin file idk why it refuses to run
the code:
#include<iostream>
int main()
{
std::cout<<"hello";
}
and the problem is that when I try to use the "code runner extension" it is not working so I just press f5 and then when I get the error messages which says at first "could not find the task file'c/c++:g++.exe build active file' " and I get three options 1:debug anyway
2:configure task
3:cancel
when I choose debug anyway I get this error here
Since you're on windows consider installing Visual Studio or CLion. They're more beginner friendly - VSCode can get tricky to run c++ on windows. Either way, looks like you're trying to run your project without building it first. There should be a build option right next to the run option. Try building it, then running. The build is what compiles and creates the project.exe file, which is what the compiler is saying isn't there.
The referenced IDE's always auto-build on run, so there's that
If you're familiar with using the command line, these commands will do what you want, assuming the .cpp file is in your current directory.
g++ <FILENAME>
./a.out
There are wonderful flags you can add to the first command (the compiling command) like -Wall, -Wextra, -o, and many more. But, since it seems like you're just starting out, there's no need to worry about those!
If you're not familiar with the command line, I would encourage you to become familiar! It is an extremely powerful tool for a programmer. Here is a YouTube video that talks about it.

Command line cpp compile isn't working properly

First of all, I made a simple program to test if compiling was working properly, it is as follows:
#include <iostream>
int main() {
std::cout << "Oi!";
}
Quite simple indeed, should compile properly, right? Wrong.
I am using MinGW for Windows 10, just to let you know.
I tried compiling it using "cpp <file name>.cpp -o a.exe" and was, first time, going through with the compile, but once I tried to execute the file it would send me this:
./a.exe: line 14: namespace: command not found
./a.exe: line 20: syntax error near unexpected token `('
./a.exe: line 20: ` typedef decltype(nullptr) nullptr_t;'
Clearly something was wrong, so I searched for a solution, found out someone had a similar problem and doing a reinstall solved it, so I went to the MinGW installation manager, noticed the C++ compiler library wasn't installed and installed it. It felt I was doing alright.
I also noticed that they were using g++ instead of cpp and tried that instead, it worked properly this time, but I would like to note that I have "git bash" installed, so I assume it used "git bash" 's command and not MinGW's.
So I opened cmd and tried using cpp, once I tried executing the program cmd said that the software wasn't compatible with the version of windows being executed, that doesn't sound right. I did a verbose compile with cpp and noticed this oddity:
#include <...> search starts here:
c:\mingw\bin\../lib/gcc/mingw32/6.3.0/include/c++
c:\mingw\bin\../lib/gcc/mingw32/6.3.0/include/c++/mingw32
c:\mingw\bin\../lib/gcc/mingw32/6.3.0/include/c++/backward
c:\mingw\bin\../lib/gcc/mingw32/6.3.0/include
c:\mingw\bin\../lib/gcc/mingw32/6.3.0/../../../../include
c:\mingw\bin\../lib/gcc/mingw32/6.3.0/include-fixed
End of search list.
That doesn't follow Windows's file path standard...
Does it have anything to do with the problems I am facing? I just want things to compile! ;w;
As mentioned above, you need to use g++ to compile your code. Try the command g++ --version If you get any result that doesn't include a version number you need to install g++. Here is a guide that may be helpful.
https://techsupportwhale.com/install-gcc-compiler-on-windows/

Script for Notepad++ NppExec for C++ in ubuntu

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.
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.

No such file or directory "ruby/config.h" when trying to compile C++ into Ruby using SWIG

I'm trying to get a basic example running using SWIG to convert a C++ file into Ruby. I have Ruby 2.0.0p451 (64 bit version) installed and I've also installed the 64-bit DevKit. I'm running Windows 7 and trying to use swigwin-2.0.12. Finally, I am using the GCC C++ compiler supplied by Mingw-builds for the 64-bit version of Windows.
I have the basic C++ hello world program as shown below.
#include <iostream>
#include <cstdlib>
using namespace std;
main()
{
cout << "Hello World!";
system("pause");
return 0;
}
At the command prompt, I use the command:
swig -module -c++ -ruby hello_world.cpp
This completes fine and produces a file titled hello_world_wrap.cxx. However, when I receive an error when I try to compile the .cxx file using the command:
g++ -fPIC -c hello_world_wrap.cxx -IC:\Ruby200-x64\include\ruby-2.0.0
The error I am receiving is:
All the research I've done has pointed me to an installation of the incorrect DevKit, but I don't think this is my issue. I've made sure to download the 64-bit version of Ruby and the DevKit. I've checked the folder specified in the error, and there is no config.h file. I'm not sure why the config.h file does not exist or why ruby.h is trying to load it.
Any thoughts?
Check that C:\Ruby200-x64\include\ruby-2.0.0\ruby\config.h exists. If not, find it and fix the path.
Update:
Check if there is a ruby.h in the same folder. If there is then just use -IC:\Ruby200-x64\include\ruby-2.0.0\ruby\x64-mingw instead. Otherwise try adding a second -I, for this extra path. I agree with you this is a little strange (not so much the former, but definitely if you have to have two -I). The script at https://groups.google.com/forum/m/#!topic/comp.lang.ruby/RpjuvXpFI30 suggests that this might be normal, I.e. you need one -I for platform-independent headers and one for platform-dependent.

What is a 'shebang' line?

Currently I'm trying to start programming on my new Mac. I installed TextWrangler, and chose C++ as my language of choice; since I have some prior knowledge of it, from when I used Windows.
So, I wrote the ever so common "Hello World" program. Although, when I tried to run it, I got an error:
"This file doesn’t appear to contain a valid ‘shebang’ line (application error code: 13304)"
I tried searching the error code to find out how to fix this, but I couldn't find anything.. I have no idea what a 'shebang' line is... Can someone help me out?
You need to compile it with a compiler first. I assume you tried to run the source file like ./source but C++ doesn't work this way.
With some compilers however, you can provide a shebang-line as the first line of the source file (the #! is known as shebang or crunchbang, hence the name), like so:
#!/path/to/compiler
So that the shell knows what application is used to run that sort of file, and when you attempt to run the source file by itself, the compiler will compile and run it for you. That's a compiler-dependent feature though, so I recommend just plain compiling with G++ or whatever Macs use to get an executable, then run that.
While I wouldn't recommend it for regular C++ development, I'm using a simple shell script wrapper for small C++ utilities. Here is a Hello World example:
#if 0 // -- build and run wrapper script for C++ ------------------------------
TMP=$(mktemp -d)
c++ -o ${TMP}/a.out ${0} && ${TMP}/a.out ${#:1} ; RV=${?}
rm -rf ${TMP}
exit ${RV}
#endif // ----------------------------------------------------------------------
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "Hello world" << std::endl;
return 0;
}
It does appear that you are trying to run the source file directly, however you will need to compile using a C++ compiler, such as that included in the gcc (GNU Compiler Collection) which contains the C++ compiler g++ for the Mac. It is not included with the Mac, you have to download it first:
from http://www.tech-recipes.com/rx/726/mac-os-x-install-gcc-compiler/ : "To install the gcc compiler, download the xcode package from http://connect.apple.com/. You’ll need to register for an Apple Developer Connection account. Once you’ve registered, login and click Download Software and then Developer Tools. Find the Download link next to Xcode Tools (version) – CD Image and click it!"
Once it's installed, if you are going for a quick Hello World, then, from a terminal window in the directory of your source file, you can execute the command g++ HelloWorld.cpp -o HelloWorld. Then you should be able to run it as ./HelloWorld.
Also, if you're coming from a Visual Studio world, you might want to give Mono and MonoDevelop a try. Mono is a free implementation of C# (and other languages), and MonoDevelop is an IDE which is very similar to Visual Studio. MonoDevelop supports C# and other .NET languages, including Visual Basic .NET, as well as C/C++ development. I have not used it extensively, but it does seem to be very similar to VS, so you won't have to learn new everything all in a day. I also have used KDevelop, which I liked a lot while I was using it, although that's been a while now. It has a lot of support for GNU-style development in C/C++, and was very powerful as I recall.
Good luck with your endeavors!
Links:
Mono: http://mono-project.com/Main_Page
MonoDevelop: http://monodevelop.com/
KDevelop: http://kdevelop.org/
shebang is http://en.wikipedia.org/wiki/Shebang_%28Unix%29.
not sure why your program is not running. you will need to compile and link to make an executable.
What I find confusing (/interesting) is C++ program giving "Shebang line" error. Shebang line is a way for the Unix like operating system to specify which program should be used to interpret the rest of the file. The shebang line usually points to the path of the interpreter. C++ is a compiled language and does not have interpreter for it.
To get the real technical details of how shebang lines work, do a man execve and get that man page online here - man execve.
If you're on a mac then doing something like this on the commandline:
g++ -o program program.cpp
Will compile and link your program into an executable called program. Then you can run it like:
./program
The reason you got the 'shebang' error is probably because you tried to run the cpp file like:
./program.cpp
And the shell tries to find an interpreter to run the code in the file. Because this is C++ there is no relevant interpreter but if your file contains Python or Bash then having a line like this
#!/usr/bin/python
at the 1st line in your source file will tell the shell to use the python interpreter
The lines that start with a pattern like this: #!/.../.../.. is called a shebang line. In other words, a shebang is the character sequence consisting of the characters number sign and exclamation mark (#!).In Unix-like operating systems, when a text file with a shebang is used as if it is an executable, the program loader mechanism parses the rest of the file's initial line as an interpreter directive. The loader executes the specified interpreter program, passing to it as an argument the path that was initially used when attempting to run the script, so that the program may use the file as input data.