tags:

views:

83

answers:

6

I am trying to run a C/C++ program on Ubuntu.

So at first g++ didn't work at all in the shell, so I installed it using the command

sudo aptitude update && sudo aptitude install g++

so it installed it, and when I wrote the most simplest program it compiled

g++ -Wall a.cpp -o d

But when i tried to execute it just wrote "d" on the command line and states that the command is not found, but if I type ls in the shell it shows me that there is an executable file named d

Glad if someone can clear things out for me

+2  A: 

Probably because the current directory is not in your path. Try

$ ./d
gnibbler
A: 

When executing a file that isn't in one of the normal bin directories (just think of it as something that you didn't install from a package or that didn't come from the OS) you need to supply the path to the file.

In this case, what you want is ./d

SoapBox
thanx for the really fast response..i used now ./d and it worked.but it is weird since i ussually work on a linux system and there it is enough to write "d" (if you are in the same directory
darven
Ubuntu is a Linux system. The difference is that on one system your `$PATH` includes `.` which is a bad idea for security.
Dennis Williamson
+7  A: 

You have to use ./d (if you are in the directory) or the complete path of your executable.

When you type "d", your OS looks automatically into the directories of $PATH. You can figure out what is the complete path of any executable (like ls or rm) with the command "which".

If it don't work check that the file is executable ("x" flag) and if needed, just add it with

chmod +x file
Elenaher
+1, but g++ sets the file to be executable by default and chmod isn't needed here. While you're at it, though, good to mention how to check that flag (ls -l being the easiest).
Roger Pate
A: 

Could also be rights problem, you may need to set the file to be executable. See chmod command.

Jaydee
A: 

You need to give the command line the full path to your file so that it knows exactly where it is. You can do this by using the . prefix, which is shorthand for "the path to the current directory". Therefore, if you are in the same directory as the d file, you should be able to type:

./d

And this should run your program.

Stephen
A: 

I don't like the solution I will propose now, but I do give it to some friends that are used to AIX or Windows command prompt (where you don't have to use ./) and changed to some Linux flavor:
- Add "./" to your $PATH environment variable (I'd put it in the end, but it's up to you to choose its priority). You'll then be able to just use "d" anytime.

Filipe Pina