Need assistance with PATH variables - c++

I am compiling C++ programs in Notepad++ and using command prompt to execute and run the programs. Initially I had this problem where the cmd said
"g++" was not a recognized command.
I changed path variable and it was fine. But later when I was started Eclipse, it would not start. I had to change PATH variable again.
So my question is do I have to change the PATH variable every time I switch to running c++ and Eclipse or is there an alternative?

Here is a simple tutorial if you're on windows 7 :
http://geekswithblogs.net/renso/archive/2009/10/21/how-to-set-the-windows-path-in-windows-7.aspx
Once you set PATH variables, make sure to restart your computer. I've been in a similar situation and it was me just getting ahead of myself.

Related

c++ executable runs from command line, but not from eclipse

I'm trying to follow a tutorial using the SDL2 library. I've followed the instructions here verbatim.
The program compiles fine, but when I try to run it within eclipse I get the following error when calling SDL_Init(SDL_INIT_VIDEO):
No available video device
After some research I decided this was because SDL2 had not been correctly linked to any display drivers so wasted several hours installing it from source, and trying various fixes suggested on various forums.
After following another tutorial I found that there was nothing wrong with my SDL2 installation. And in fact when I run the executable created by the eclipse project from the terminal, it runs without any problems.
There are similar questions (for example here), but I can't find one where the error occurs from within eclipse, but not the terminal.
Any pointers would be greatly appreciated. I suspect it may be to do with an environment variable not being set, but not sure which or why. Based on answers on SO I added the DISPLAY environment variable and set it to :0 in the project set-up but with no luck.
Update: I found a way to quickly add all of my bash environment variables to my eclipse project and I still get the No available video device error.
Update 2: Turns out I wasn't adding environment variables in the right place (I was adding them to the C++ build environment, not the Run environment; which is obviously where the problem was giving application was building but not running). Posted answer below.
It turns out it was an environment variable problem. To fix you need to add the environment variable DISPLAY to your project and set it to :0.0.
To do this right-click on your project, then select Run As >> Run Configurations...
Then select your application in the left-hand panel. Select the Environment tab on the right. Click New... and then enter DISPLAY in the Name: field, and :0.0 in the Value: field.
Click Apply and then Run, and it should work. Thanks to #Anon Mail for pointing me in the direction of environment variables.

gnuplot command not working with system() function in C++

My gnuplot command is not working in my C++ program. I am trying to run gnuplot command in C++ program like this:
system("gnuplot");
It gives the error:
'gnuplot' is not recognized as an internal or external command. etc.
when I try to run gnuplot in cmd, it works fine.
Any one have idea that why gnuplot command in not working with system() function in C++?
The reason is probably that the environment you execute your C++ program in doesn't tell your operating system to look in the right places to find your gnuplot executable.
Try the full path to the GNU Plot executable, include the file suffix (.exe) if you're on Windows, or make sure to set the PATH environment variable to include the directory in which your gnuplot executable is.
Check whether the path to the gnuplot is in your PATH environment variable. Or alternatively, you can use the absolut path to it when calling system()
Thanks you for answers friends,
I found the solution finally: After editing the environment variable $path, one has to restart the visual studio to get the latest value of environment variable. When I restarted my visual studio, it works.
So when ever you change your any environment variable, just restart visual studio (in case you are using it).
Thanks and kind regards,
Awais

Can't run C++ in NetBeans: "No Shell Found" error

I'm trying to learn C++ using NetBeans but even though I have CYGWIN and everything set up in my PATH, I keep getting an error that says: "No shell found. Cannot proceed. Please install either CYGWIN or Msys."
I don't know what Msys is but since the error says "or" I assume that if I have CYGWIN that I don't need to have Msys.
I'm trying to run the basic "Hello World!" tutorial but this error from what I've seen isn't covered. I'm getting aggravated because I have a project I need to have done in a few weeks.
If anyone has any answers for me, that would be great. I can supply screenshots if you need them.
Cygwin alone is not enough, first of all you have to check if you installed C++/gcc/gdb packages in your Cygwin.
From Cygwin/Net beans docs:
Open the Control Panel (Start > Settings > Control Panel) and double-click the System program.
Select the Advanced tab and click Environment Variables.
In the System Variables panel of the Environment Variables dialog, select the Path variable and click Edit.
Add the path to the cygwin-directory\bin directory to the Path variable, and click OK. By default, cygwin-directory is C:\cygwin. Directory names must be separated with a semicolon.
Click OK in the Environment Variables dialog and the System Properties dialog.
If it fails you could try to Re-Install Netbeans from/within an cygwin/bash instance start the netbeans from a cygwin/bash instance.
Netbeans should automatically detect gdb/g++
PS: I'd prefer to use a good Gnu/Linux distro
I had the same problem with 8.1.
Adjusting the %PATH%-variable - in my case adding C:\msys64\usr\bin - solved it (as wdavilaneto's slightly verbose answer suggested).
This is not an answer but it adds to this question, I know that isn't very objective but in this case there may be a problem with Netbeans. I have 7.3 so this could be the reason. I am getting the same error but it used to work just fine, then one day it just stopped working and couldn't find the Shell. I have everything you need to make C/C++ work for Netbeans and it was working, for a while too!
It is rather old, but I've had the same issue a moment ago. It "Solved itself" by Creating a new "welcome sample" project and then made it run, then went back to my original project and made it run again. For me, it solved the problem. Probably it is related to an issue with Netbeans as Cian said.
Btw, I'm with Netbeans 8.1.
Make sure the shell is in your path! Depending whether you have Cygwin, Mingw32, Mingw32, TDM Mingw... it will be somewhere here:
c:\<installation path>\usr/bin
Hmh, I have 2 C compilers one for 64bit and one for 32bit set in NetBeans. When I had 32bit compiler without 64bit one then compiling went fine but when I have installed 64bit then NetBeans has started to do some problems, firstly everything went fine but then I started to get this problem to. For me fix is to switch from 64bit compiler back to 32bit compiler, then compile my program and then go back to 64bit compiler and now I can compile it with 64bit compile... Not sure why is this fixing it.
I have this problem with Netbeans 10.
Computer is Windows 10 x64.
Resolved by following the answer given by TNT.
Problem was when start building my project the said "no shell" (the topic of this posting) dialog box popped up. Since there was no command prompt, the build tools cannot run - process cannot spawn.
Solution was to give the correct path (environment variable). Since I am using MSYS, Since I am using MSYS, adding
F:\msys64\usr\bin
to my PATH made it work.

Building Qt cross compile from windows

[edit] Sorry, I out thought myself. I was using a .bat file to set environment variables that wasn't set up properly. When I went to a straight VS2005 command prompt, the configure ran fine. Sorry for the noise.[/edit]
I'm trying to compile qt-everywhere-opensource for embedded. I'm using MSVC2005. However, I guess I am confused on the process. I am getting compiler errors during the configure step. I thought the configure step was just trying to generate the needed makefiles, so I'm not sure what it is trying to compile.
I expected to modify the mkspec, but I'm not sure if during configure I should point to windows headers or sdk headers. I know during the build phase I should point to sdk headers, but I'm not getting that far.
I can change the errors by modifying INCPATH, there's also a QMAKE_INCDIR that seems to have an effect. It occurred to me that since I pulled the source, maybe configure needs to build the compiler tools, in which case I should point to MSVC headers. I also tried downloading the SDK and adding the path to it's bin folder to my path ahead of the -everywhere- source, but that didn't fix the problem and I don't want to jack up my system too much testing things.
Hope someone out there can help!
When you install Qt from source under Win32, you must:
Extend the PATH variable to include $(QTDIR)\bin, where $(QTDIR) is the directory where you installed Qt.
Open a Visual Studio command prompt in $(QTDIR); a plain old Windows command prompt won't do (unless you run vcvars.bat to load Visual Studio's environment variables; but opening a Visual Studio command prompt directly is better).
At this point, configure should run properly, after which you can run nmake.
I suggest that you clear your previous installation attempts from your system before you try these steps.

MinGW Distro installation issue

I'm trying to install MinGW distro following the steps here: http://nuwen.net/mingw.html#install
But, when I try to run: gcc --version
at my command line I get the following:
'gcc' is not recognized as an internal or external command,
operable program or batch file.
Why is that?
Thanks.
You need to set up your PATH environment variable so that the command interpreter finds the gcc program.
E.g. (since you’re working in the Windows [cmd.exe] command interpreter)
set path=%path%;%programfiles%\mingw\bin
You have to use the path that applies to your system and your installation of the compiler.
You can set up a more permanent path via the Environment button in the System applet in the Control Panel. You can also do it more low level via the registry (e.g. command regedit). And in other ways.
By the way,
for C++ programming use g++, do not use gcc directly.
At least if you want to avoid trouble. Of course you can do manually what g++ does. But much easier to use g++; that’s what it’s for.
Cheers & hth.,
The command prompt cannot find the program 'gcc'. It's most likely because you have something wrong with the environment variable. If the pathname given in the environment variable is at all incorrect or non-existent (if you have the folder in another place), then command prompt will not be able to find it.