I installed a virtual machine VMWare Player Ubuntu on my win XP.
At first when ever I tried to compile my program it didn't work so I installed something that allowed me to use G++
but now when i run:
g++ - Wall a.cpp -o out
It creates an executable out. But if I run it by the command out
it gives me an error
bash: out command not found
Does any one know the problem?
Thanks
The compiler is most likely compiling just fine.
Try running the program like this:
./out
It should not matter, if Ubuntu is installed in a virtual environment, at all. As I see it, the only problem is running the program :-)
Because . isn't in the PATH by default, you need to give bash the exact name of your executable; it won't find an executable file in your current working directory. (This is a good thing; it vastly improves security on multiple-user systems, and the habit is a good one to be in on single-user systems.)
Try: ./out.
I suggest giving the filename something better than out -- a.out is the typical output filename for historical reasons, but nothing says you have to keep it or anything like it. :)
Related
Well I am relatively new in computer's world, and I learned programming on a virtual machine using linux S.O. I am using minGW32 command prompt, and I can compile and run my c codes as needed, however I recently installed gdb debugger (for debugging my programms), and it is bit uncomfortable to write:
"c:\mingw\bin\gdb.exe" exe_name
in order to debug my programs. Is there a way for having something like:
gdb exe_name
like in linux?
Thanks in advance.
extra question: And the same for valgrind?
best regards
You should add the path "c:\mingw\bin" in your environment variable. This way whenever you type gdb on command prompt, it would search from the above path.
And the same for valgrind?
Till date Valgrind does not run on Windows platform.
I'm new on C programming and I had been wondering what command on cmd works just the same as makefiles on Linux. You see, the OS of the computers we use in school is Linux and Mac and my laptop is Windows 8 and so the text editor I use is only Notepad++. I started coding just a few weeks from now and I'm going crazy since I got something to hand in and I cannot figure out what command to use. Plus, I do not have Visual Studio or whatsoever installed on my computer. It might just be a simple problem for you guys so someone help me?
So the basic HelloWorld.c:
#include <stdio.h>
int main ()
{
printf("HelloWorld\n");
return 0;
}
to compile: gcc HelloWorld.c -o HelloWorld -Wall
to run: HelloWorld
#Beta That's how I do it on Windows
Sounds like you need some tools to get your code done.
Option 1:
You said you don't have visual studio, did that mean you wanted it?
Microsoft offers Visual Studio Express for free, I have a 2010 version that I use when I need to reproduce something on there, but there's a 2012 version listed as well.
Option 2:
You said you have Windows but they use Linux at your school? Well have you ever heard of Oracle's VirtualBox? It's a very simple application that lets you run a Linux box inside your windows machine, and it's free! Go to Oracle's site and download VirtualBox then go to the site of your favorite Linux distro and download a .iso image of it (for example if you were feeling Minty you could go get a iso here)
Then you can follow the instructions to set up and "install" the iso in the virtual machine and voila! You have Linux at home. Gcc/Make and everything you're used to.
Option 3:
If you just want Make GCC and such tools you can get them from the MinGW site. You can set things in your windows environment variables such that you can call gcc and make right from the command prompt wherever it is.
So far, so good. Now try make -v, to determine whether you have Make installed, and if so which version.
EDIT:
All right, let's try a very simple makefile:
all:
#echo hello
This is just a text file called makefile. The whitespace at the beginning of the second line is a TAB, not spaces. (I'll explain the '#' later.) Once you have written this file, try make. It should say hello.
I've read http://dinosaur.compilertools.net/bison/bison_5.html#SEC25. But following those instruction i can not compile my yacc file using bison
How do i compile my file in windows 7 ... ?
Please help me to do this.
There is a common reason why bison will not operate properly on Windows and is mentioned in the install instructions but often overlooked. It is important that the name of the location of the directory that bison (and flex) is installed in (the path) does not contain a space. in particular this means that it cannot be placed under C:\Program Files\. The problem is that this directory might be suggest as the default install location. It is sometimes necessary to manually change the default to somethings else (like C:\GnuWin\ or similar). It is also usually necessary to manually add the appropriate directory to the PATH environment variable. Once this has been done there should be no problems in running bison and flex from the command prompt. It would normally be used in the following way:
flex lang.l
bison lang.y
gcc -o lang.exe lang.tab.c -lfl
It is not necessary to install MinGW, Cygwin or use Powershell or a VM or use linux as indicated by #DavidHefferman
If you still can't get it right, I even have an instructional video!
Using those Unix commands in Windows PowerShell might work, but I'm not sure and I'm currently not on Windows, so I can't check it.
If that fails you could try installing Cygwin (a basic Linux environment in Windows). You'd have to select the bison package during installation. It comes with its own shell that you can use.
Actually my personal favorite when programming under Windows is setting up a virtual machine with VirtualBox. That way you could use a real Linux environment without actually leaving Windows.
Good luck!
I have installed Cygwin on my system. But when I try to use the gcc command it says:
bash: gcc: command not found
Can anyone provide me the solution, please?
In my installation there was no generic gcc command either, so I made a symlink for it:
cd /usr/bin
ln -s i686-pc-cygwin-gcc-3.4.4.exe gcc
Now check if it worked by doing which gcc which should give you /usr/bin/gcc and then gcc should give you gcc: no input files. Note that your version of i686-pc-cygwin-gcc-3.4.4.exe may be different. Check in /usr/bin for it.
Maybe during installation of Cygwin you have not selected gcc, gdb and make packages.
I had the same problem and it was resolved after I selected above-mentioned packages.
A couple of things:
I always install the whole Cygwin package. Earlier versions had troubles with dependencies that are fixed now, I believe, but it's still a good habit. You never know when you may need the most esoteric bit of Cygwin.
You may have to change your path. All the tools can generally be found okay if you're running inside the Cygwin bash shell but that's not necessarily the case from cmd.exe.
It's unlikely to be that last one since your error message is coming from bash itself, so I'm pretty certain that's how you're running it.
Have a look to make sure you have /usr/bin/gcc from within bash and that your path includes /usr/bin somewhere:
pax> echo $PATH
/usr/local/bin:/usr/bin:/bin:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS
pax> which gcc
/usr/bin/gcc
If it's not there, go back and re-install everything (or the relevant development package if you don't want everything). If it is there and your path doesn't have its location, change your path, in either /etc/profile or the equivalent in your home directory.
Another related issue that wasn't mentioned here, is from the command line the compiler needs the environment path variable updated to find the location of the c++ header files. In windows you can just update the path environment using the 'advanced system properties' GUI and add the location of the c++ include files. This will update the PATH environment variable in Windows cmd & Cygwin automatically upon restarting the shell.
To update your PATH from Linux or the Cygwin shell type... PATH=$PATH:/your_path_here Example:PATH=$PATH:/cygdrive/c/cygwin/lib/gcc/i686-pc-mingw32/4.7.3/include/c++ Also a good idea to add just the include directory as well: PATH=$PATH:/cygdrive/c/cygwin/lib/gcc/i686-pc-mingw32/4.7.3/include/ ...or check the proper directories for the location of your installation's include files, I recommend installing mingw for use with Cygwin, which is envoked with g++.
To install additional needed packages in Cygwin re-run the Cygwin install utility & check install from Internet to add packages from web repositories and add mingw-gcc-g++ & mingw-binutils. To compile your code: g++ hello.cpp -o hello
If using the gcc utility instead compile with the command: gcc hello.cpp -o hello -lstdc++ ... to get your executable.
As long as you have either gcc or mingw installed and the path to the c++ include files is in your path environment, the commands will work.
There is another hard to spot mistake could also cause this error,
If your Makefile uses PATH as variable, the gcc not found error could happen.
This is because it changes the system path temporarily.
I took a lot of time checking the cygwin environment setting to discover this, so I'll leave it here in case this helps anyone finding their way here.
One one machine, everything compiles fine. On another machine, it complains about the -ly option when I use gcc to create the output file. If I remove the -ly option, then it makes the program, but then it runs differently. What's happening. How can I get the program to run correctly on this linux machine?
You should check to see if you have the same flex/bison versions...
YACC program options (and generated output) vary from OS to OS. Bison might be more consistent.