Jump to content

What does this mean "No such file or directory"?


Recommended Posts

hi,

 

i m using mandriva linux le 2005.

 

i am trying to do learn linux and if possible do some c/c++ programming on it.

 

i tried to look for the compiler (as far as i know i need to have it in order to compile any program) and my linux distro seems to be having it as this is the message i got in return

 

"Reading specs from use/lib......................

 

...............................gcc version 3.4.3 (Mandrakelinux 10.2 3.4.3 -mdk)"

 

i thought my linux installation is having a compiler so i tried to write a simple c program which is as follows

 

#include <stdio.h>

void main()

{

printf("Hello World From About\n");

}

 

 

i used a text editor called KWrite and then save the file as hello.c on the desktop.then i closed it and restarted the Konsole and wrote something like this

 

gcc -o hello hello.c

 

but the message came as "No such file or directory"

 

i m not sure what was going wrong. can you please help me with this as i m an idiot when it comes to linux and any kind of programming.thanks..

Link to comment
Share on other sites

The message means the compiler can't find the specified file hello.c. Try ./hello.c
Um... it's probably not ./hello.c as it's saved on the desktop, so it would be Desktop/hello.c. However I wouldn't save the file on the desktop, cos all the files that get generated will make things messy there. I'd save it to a new directory, let's say "hello". Then everything to do with this program will be all in one place, nice and tidy :)

 

Then from your console, go into this directory and try your compile again:

cd hello
gcc -o hello hello.c

If it has worked, you should be able to see the generated files:

ls

and you should see one called "hello". Run this executable like this:

./hello

Try that and let us know if it works!

Link to comment
Share on other sites

The message means the compiler can't find the specified file hello.c. Try ./hello.c
Um... it's probably not ./hello.c as it's saved on the desktop, so it would be Desktop/hello.c.

unless of course you're already in ~/Desktop, in which case ./hello.c would work ;)

Link to comment
Share on other sites

unless of course you're already in ~/Desktop, in which case ./hello.c would work ;)

Yeah, but then so would hello.c ;)

 

He said he restarted the console and typed gcc -o hello hello.c, so I guessed he's probably still in ~.

Link to comment
Share on other sites

i'm just messing with ya.
tyme: :cheesy:

 

But this raises an interesting question which I didn't find obvious at first, and I imagine for others too it can be confusing - what IS the difference between hello.c and ./hello.c ? When should you use one and not the other?

 

And the answer is, as far as I can tell, there is no difference, if one works then the other works. If it's a parameter to a program call. If you're doing for example an ls, or less, or vi, or tar, or cp, or java -jar, and giving it a filename, then it makes no difference if you specify it as filename or ./filename or ~/wherever/filename or ../wherever/./././filename as long as your path resolves to the file you want.

 

The only time the ./ is necessary is when you're running a program, and this executable is sitting in the current directory. (If it's in a subdirectory then you just run subdir/prog, you don't need subdir/./prog). If you just type the executable name then you're asking the shell to find the program for you, and it'll look in /usr/bin for it, and other places too, but it won't by default look in your current directory unless you explicitly specify the path ./. This is why it can be confusing and it's tempting to think that the ./ is always necessary to find files - it's only necessary to find executables in the current directory.

 

I think (correct me if I'm wrong) that this setting to not include . in the executable path is deliberately done to stop you accidentally calling executables which aren't installed system-wide. So if you somehow had an executable in your ~ called ls which did something you didn't expect, then typing "ls" would still be safe and not call this executable - you'd have to definitely say you wanted to run that ls and not the 'normal' ls. But then I'm sure aliases could get some unpredictable behaviour happening anyway.

 

So anyway, long story short, that's why you need to run the resulting executable with ./hello but you don't need to call gcc with the parameter ./hello.c.

 

Sorry if that got a bit rambly, but as I said I found it non-obvious so maybe that ramble might help someone.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...