Ask Your Question

compiling using g++

asked 2014-03-06 05:34:24 -0500

Oded gravatar image

updated 2014-03-07 04:25:31 -0500

Jomoos gravatar image

After installing gcc and gcc-c++ using yum, I tried to compile some extremely simple c++ programs, those of the kind that print "hello".

  1. I used g++ -c prog.o prog.cpp and retrived the prog.o file without any problems
  2. I used g++ -o prog.exe prog.o and retrived the prog.exe file without any problems

BUT, when i tried to run the program in the terminal by writing prog, I get

bash: prog: command not found...

does anyone knows why?? I've been trying to do that for some hours now...

edit retag flag offensive close merge delete



Can you run "ls -la prog.exe" ? Maybe the execution flag is not set.

keramidas gravatar imagekeramidas ( 2014-03-09 13:06:17 -0500 )edit

2 Answers

Sort by » oldest newest most voted

answered 2014-03-06 07:31:21 -0500

skytux gravatar image

You should run prog.exe, not prog, because you called it prog.exe:




edit flag offensive delete link more

answered 2014-03-09 01:33:32 -0500

Oded gravatar image

updated 2014-03-09 01:34:11 -0500

Of course i tried that too, neigher works. Did i have to write "./prog.exe"? Writing "prog.exe" is not enough? Thanks again

edit flag offensive delete link more


So, apperantly Mr. skytux was partly right. It doesn't matter if i write "prog" or "prog.exe", but adding ./ before "prog" solved the problem. I realy wonder why... what does ./ means? i mean, i was in the right folder that contained the file prog.exe...

Oded gravatar imageOded ( 2014-03-09 17:03:00 -0500 )edit

Sounds like an execution flag is amiss... chmod +x prog.exe ...without which bash (or any other shell) tries to find 'prog' from the places told in $PATH variable.

"./" more or less stands for "within the current directory", and AFAIK implies execution whether executable flag is set or not.

daikane gravatar imagedaikane ( 2014-03-11 18:59:49 -0500 )edit

Question Tools

1 follower


Asked: 2014-03-06 05:34:24 -0500

Seen: 224 times

Last updated: Mar 09 '14