LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-31-2011, 05:57 PM   #1
vonelli
Member
 
Registered: Mar 2008
Posts: 33

Rep: Reputation: 1
C++ program compiled in Fedora 14 do not run


I am very new in c programming. I could not get a simple compiled program to run, I am using Fedora 14. To learn the correct way I sign in to http://mrbook.org/tutorial/make/ and fallow the examples listed they all compile and generate the executable file but none run. To run them I try both way double chick the executable end on the command line but it does not do any thing. I will appreciate help, Vinny
 
Old 01-31-2011, 06:22 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,051

Rep: Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852
what is the program supposed to do ?
you can post source code.
usually this does it:
Code:
g++ hello.cpp -o hello.x
hello.x
 
Old 01-31-2011, 06:26 PM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Quote:
Originally Posted by schneidz
usually this does it:
Code:
g++ hello.cpp -o hello.x
hello.x
Obligatory comment:
That only works if the current directory (".") is in your PATH. If typing "hello.x" gives a "command not found" error, then try:
Code:
./hello.x
Also, please post the contents of your Makefile. That will tell us the name of the program being created and what directory it is saved to.

EDIT:
The OP's link is incorrect. It gives a 404 error. I believe this is the correct link:
Mrbook's Tutorial on Makefiles

Last edited by Dark_Helmet; 01-31-2011 at 06:37 PM.
 
Old 02-02-2011, 02:50 PM   #4
vonelli
Member
 
Registered: Mar 2008
Posts: 33

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by Dark_Helmet View Post
Obligatory comment:
That only works if the current directory (".") is in your PATH. If typing "hello.x" gives a "command not found" error, then try:
Code:
./hello.x
Also, please post the contents of your Makefile. That will tell us the name of the program being created and what directory it is saved to.

EDIT:
The OP's link is incorrect. It gives a 404 error. I believe this is the correct link:
Mrbook's Tutorial on Makefiles
-----------
I am not sure where to attach my reply, please correct me if I am using in wrong location.
sorry for wrong address, I try all the samples in that paper, here is one:

all: hello

hello: main.o factorial.o hello.o
g++ main.o factorial.o hello.o -o hello

main.o: main.cpp
g++ -c main.cpp

factorial.o: factorial.cpp
g++ -c factorial.cpp

hello.o: hello.cpp
g++ -c hello.cpp

clean:
rm -rf *o hello
This create hello executable file, but when I try to run it does not do any thing.
 
Old 02-02-2011, 03:00 PM   #5
vonelli
Member
 
Registered: Mar 2008
Posts: 33

Original Poster
Rep: Reputation: 1
C++ program compiled in Fedora 14 do not run

I think that my reply may belong here.
-----------
I am not sure where to attach my reply, please correct me if I am using in wrong location.
sorry for wrong address, I try all the samples in that paper, here is one:

all: hello

hello: main.o factorial.o hello.o
g++ main.o factorial.o hello.o -o hello

main.o: main.cpp
g++ -c main.cpp

factorial.o: factorial.cpp
g++ -c factorial.cpp

hello.o: hello.cpp
g++ -c hello.cpp

clean:
rm -rf *o hello
This create hello executable file, but when I try to run it does not do any thing.
 
Old 02-02-2011, 03:11 PM   #6
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Quote:
Originally Posted by vonelli
all: hello

hello: main.o factorial.o hello.o
g++ main.o factorial.o hello.o -o hello
If that is your Makefile, then open a terminal, cd to the directory with your Makefile, and type:
Code:
make
./hello
 
Old 02-02-2011, 04:06 PM   #7
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,051

Rep: Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852
Quote:
Originally Posted by vonelli View Post
I think that my reply may belong here.
-----------
I am not sure where to attach my reply, please correct me if I am using in wrong location.
sorry for wrong address, I try all the samples in that paper, here is one:

all: hello

hello: main.o factorial.o hello.o
g++ main.o factorial.o hello.o -o hello

main.o: main.cpp
g++ -c main.cpp

factorial.o: factorial.cpp
g++ -c factorial.cpp

hello.o: hello.cpp
g++ -c hello.cpp

clean:
rm -rf *o hello
This create hello executable file, but when I try to run it does not do any thing.
is it not printing an error like 'command no found' ?
please post the contents of hello.cpp. i suspect that it doesnt have a printf/ cout so it looks like its not doing anything.
 
Old 02-02-2011, 05:29 PM   #8
goodhombre
Member
 
Registered: Mar 2010
Location: Ungheni, Rep. Moldova
Distribution: Ubuntu
Posts: 82

Rep: Reputation: 20
hi,

try this
Code:
chmod 755 ./hello.x
./hello.x
 
Old 02-03-2011, 08:30 AM   #9
vonelli
Member
 
Registered: Mar 2008
Posts: 33

Original Poster
Rep: Reputation: 1
Thank you very much, the ./hello works. Is possible of a quick explanation of why ./ is required?
 
Old 02-03-2011, 08:43 AM   #10
goodhombre
Member
 
Registered: Mar 2010
Location: Ungheni, Rep. Moldova
Distribution: Ubuntu
Posts: 82

Rep: Reputation: 20
Hi,

Linux shell forbids running of executables without explicit ./ if the executable is not located in one of the PATH directory.
See :
Code:
echo $PATH
This prevents running of executables you are not aware of, can be a malware , backdors , etc.

Also you have to make the file executable in order to be able to run it, this is what chmod +x did.
You can check if the file is executable by running :
Code:
ls -l ./hello.x
Check this link for more details about permissions.

Last edited by goodhombre; 02-03-2011 at 08:45 AM.
 
Old 02-03-2011, 01:15 PM   #11
vonelli
Member
 
Registered: Mar 2008
Posts: 33

Original Poster
Rep: Reputation: 1
Thank you again, Vinny.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
A C program which was compiled properly in DevCPP is not compiling in Linux-Fedora. varalakshmi Linux - Newbie 2 10-30-2010 04:37 AM
Can't Run the program after compiled yunton Programming 4 04-03-2009 02:05 AM
Eclipse / Java - How do I run a compiled program jun_tuko Programming 2 10-14-2006 06:39 PM
Run executable file compiled by kylix and mysql in Fedora Core 4 aa_husni Fedora 0 09-15-2005 01:14 AM
how to run C++ compiled program legend1079 Linux - Newbie 2 03-20-2004 07:40 AM


All times are GMT -5. The time now is 04:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration