C++ Programs can't run from Notepad++ - c++

I've tried to compile the c++ programs from the Notepad++ editor.
I am using mingw64 g++ compiler here.
Added the execution script using NppExec plugin in notepad++, the script I have used is given below,
npp_save
cd $(CURRENT_DIRECTORY)
D:\mingw64\bin\g++.exe -g "$(FILE_NAME)"
Saved this script as a macro and executed to run a cpp program, but getting the System error The program can't start because libwinpthread-1.dll is missing from your computer.
The same mingw64 compiler am using in Code::Blocks and its working fine.
How we can solve this issue ?

cmd /k gcc -o "$(CURRENT_DIRECTORY)\$(NAME_PART).exe" "$(FULL_CURRENT_PATH)" && CLS && "$(CURRENT_DIRECTORY)\$(NAME_PART).exe" & PAUSE & EXIT
Press ctrl+F5 and input this command, then click 'run'. You can also save it as a shortcut.

Related

How to run C++ program from terminal VS Code

I want to run a C++ program in VS Code. All I get from Google is that click on run and debug (the play button) on top right in VS Code and my program will be up and running. I don't want to do from that. I want to do it from terminal.
Example, to run:
A Python file I do: python3 fileName.py
A Flutter program: flutter run
A Java file: javac fileName.java
A Go file: go run fileName.go
Is there any command similar like this in C++?
Apologies, I know my question is a little naïve.
i guess the short answer would be :
$ g++ -o < name-you-want-to-give> source.cpp
In place of replace it by any name like myprogram, etc.
./myprogram
This mean you had to install gcc compiler beforehand.
I need to be in my project directory and then i need to run
g++ 01inputFromUser.cpp -o 01inputFromUser && "/home/aman/Desktop/arjun/cpp/"01inputFromUser
so this was what I was looking for
g++ fileName.cpp -o fileName && "/path/to/project/"fileName

VSCode Extension Run Code can't run C++ in terminal

I am new in C++. I like VSCode very much. I want to run my C++ code in VSCode and so I am using MinGW and Run Code Extension of VSCode.
MinGW setup worked and I could also run my C++ code in the output terminal in VSCode, but when I enabled Code Runner in the settings to run my code in the terminal (so that I can take inputs), I am getting this error:
bash: cd: d:\CodeForces" && g++ inSearchOfAnEasyProblem.cpp -o inSearchOfAnEasyProblem && d:CodeForces"inSearchOfAnEasyProblem: No such file or directory
My Folder structure is: d://CodeForces//inSearchOfAnEasyProblem.cpp
I am trying to run this file: inSearchOfAnEasyProblem.cpp
I am using the Bash terminal. I tried to change the terminal to cmd, but when I click the run button of code runner, it always runs in a bash terminal.
enter image description here
Can anyone please help me? I would have been grateful.

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.

Unable to build and run c++ code in visual studio code

I have setup the correct path for mingw and am successfully able to compile my code using terminal in vscode. But when I press ctrl+shift+b to build i get the following error in my terminal
Executing task: C:\MinGW\bin\g++.exe -g 'c:\Users\Ansh Kapoor\Desktop\cpp\main.cpp' -o 'c:\Users\Ansh
Kapoor\Desktop\cpp\main.exe'<
/usr/bin/bash: C:MinGWbing++.exe: command not found
The terminal process terminated with exit code: 127
whereas the same code is successfully executed when I write
g++ main.cpp -o 'main.exe'
Now I have checked the path and environment variables and all those things are correct.
The error in finding the proper path was because of using git bash as the terminal rather than windows powershell or cmd.

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

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.