LinuxQuestions.org
Review your favorite Linux distribution.
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 04-28-2003, 11:25 PM   #1
freemind
LQ Newbie
 
Registered: Apr 2003
Posts: 7

Rep: Reputation: 0
Unhappy something wrong with gcc


I made a simple C program (just printing out "Hello") to test gcc compiler in my newly installed Redhat 7.3 system. I type " gcc -o test test.cpp" and it compiled without any complains. Then I type "test" to run the program, but nothing shows up. I don't know what is wrong. Do I need to set the path for gcc even though it comes with the installation of the OS? Please advise, many thanks.
 
Old 04-29-2003, 01:33 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 12,174

Rep: Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784
Unless your program is in your current path enviroment you need to either type in the full path to the program or use the ./ shortcut.

In the directory where test is located:
./test
 
Old 04-29-2003, 11:05 AM   #3
freemind
LQ Newbie
 
Registered: Apr 2003
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks.
 
Old 04-29-2003, 01:35 PM   #4
blinux1
Member
 
Registered: Nov 2002
Location: Pennsylvania
Distribution: Mandrake 9.1 and Redhat 9
Posts: 144

Rep: Reputation: 15
you can also put it in a path directory like /bin or /sbin/
 
Old 04-29-2003, 03:22 PM   #5
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,539

Rep: Reputation: 149Reputation: 149
Or you can add the directory it's in to your PATH:
export PATH=$PATH:/somewhere
 
Old 04-30-2003, 06:18 AM   #6
KDE4me
Member
 
Registered: Apr 2003
Location: Australia
Distribution: RedHat 9.0 / Slackware 9.0/ FreeBSD 4.8 / Solaris 8 x86 / Mandrake 9.0
Posts: 90

Rep: Reputation: 15
This might help you if the paths don't work (I had a similar problem)
[problems running c in bash]
http://www.linuxquestions.org/questi...threadid=57409
 
Old 04-30-2003, 07:35 AM   #7
wapcaplet
Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
I don't know if this is causing your problem, but you are compiling a C++ program (at least, according to the extension) with a C compiler (gcc). Use g++ instead.
 
Old 04-30-2003, 10:26 AM   #8
shadowbird
LQ Newbie
 
Registered: Apr 2003
Distribution: RedHat
Posts: 27

Rep: Reputation: 15
Reference: Path statements.

One of the things I do is put "." as the first thing in my path. Thus, in my .bashrc file I have a statement:

export PATH=.:$PATH
 
Old 04-30-2003, 11:11 AM   #9
freemind
LQ Newbie
 
Registered: Apr 2003
Posts: 7

Original Poster
Rep: Reputation: 0
Thank you all.

I tried ./test, it works. Here I have two more questions regarding your suggestions:

1. I want to export the Path in my .bashrc file, but I don't know what is its exact path. I use "locate gcc2.96", lots of messages come up. They are all in /usr/lib/....

2. I put "export PATH=.:$PATH" in my .bashrc file under the "#user specific aliases and functions" section. But it doesn't work. Did I do something wrong?
 
Old 04-30-2003, 11:17 AM   #10
wapcaplet
Guru
 
Registered: Feb 2003
Location: Colorado Springs, CO
Distribution: Gentoo
Posts: 2,018

Rep: Reputation: 48
If it's compiling correctly, then gcc probably already is in your path. An easy way to find out is:

which gcc

If it gives you a path to the executable, like /usr/bin/gcc, you're fine. If it says "no gcc found" or something like that, it's not in your path. Chances are, it is already in your path.

After you edit your .bashrc file, you need to restart bash. This means logging out and logging back in, if you're using terminal only, or closing and re-opening the terminal window if you're in a GUI. Or (I think this works too, haven't tried), type:

source .bashrc
 
Old 04-30-2003, 11:20 AM   #11
shadowbird
LQ Newbie
 
Registered: Apr 2003
Distribution: RedHat
Posts: 27

Rep: Reputation: 15
Reference: having put "export PATH=.:$PATH" in your .bashrc file, did you then log out and log back in again? BASH only reads that file once, when it's started.

Secondly are you using BASH as your shell. If not, then changing .bashrc won't help you, and you'll have to change the proper configuration file for your shell

-- Kevin --
 
Old 04-30-2003, 11:46 AM   #12
freemind
LQ Newbie
 
Registered: Apr 2003
Posts: 7

Original Poster
Rep: Reputation: 0
Hi Kelvin and Wapcaplet,

I tried your methods individually, and both don't work. I use "which gcc" and was given /usr/bin/gcc, then I put "export PATH=$PATH:/usr/bin/gcc" in .bashrc. Is it right?

After loging out and in and call "source .bashrc", problem is still there. Same with statement "export PATH=.:$PATH".

I think I'm using bash shell because if I type wrong commands,it gives me "bash:......"

Any idea for what is my problem? Really appreciate it.
 
Old 04-30-2003, 12:26 PM   #13
shadowbird
LQ Newbie
 
Registered: Apr 2003
Distribution: RedHat
Posts: 27

Rep: Reputation: 15
eep! Nope! Not Right!

before you changed anything, you were set up correctly to run the COMPILER but not to run the resulting executable. In other words, typing in the command

gcc -o blah blah.c

would compile the program, but if you then typed in

blah

the program wasn't found. So, the path was correct to find the compiler, but was INCORRECT to find the executable.

here's what I'd like you to do:

1. Undo any edits you made to .bashrc because we told you to make them incorrectly... ::grin::

2. Find out which shell you're using by using the command:

echo $SHELL

if it comes out looking something like /bin/bash then you're using the BASH shell (which is good).

2. IF you're using the BASH shell, add the following command at the BOTTOM of your .bashrc:

export PATH=.:$PATH

(note that's PATH equals dot colon dollar PATH)

3. Log out and back in again. (to clear out any settings that have been made prior). using the source command will add to your path but won't undue any previous incorrect path statements.

4. type the command:

echo $PATH

in the resulting output, please find either "." at the beginning of the text OR ":.:" (that's colon dot colon) somewhere in the middle (an easy way of doing that is to do the following:

(echo $PATH | grep -q '\:\.\:') && echo found

if "found" appears then it's in there.

IF it's in there (either at the beginning or in the middle) then try the following:

gcc -o blah blah.c
blah

(replace "blah" with the name of your file)

This SHOULD work (it's how my system is set up here).

Here's a copy of my .bashrc:

# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

export JAVA_HOME=/usr/java/sdk
export CATALINA_HOME=/usr/java/tomcat
export PATH=.:$PATH:/usr/local/ant/bin:/sbin:/usr/java/sdk/bin:


Note that the export statements are AT THE END.

-- Kevin --

Last edited by shadowbird; 04-30-2003 at 12:28 PM.
 
Old 04-30-2003, 02:35 PM   #14
freemind
LQ Newbie
 
Registered: Apr 2003
Posts: 7

Original Poster
Rep: Reputation: 0
Kevin, I did as what you mentioned above. Steps 1-4 are fine. But my programm is still NOT able to print out anything. When I
echo $PATH

I was given: .:.:.:/bin:/usr/bin/bin:/usr/bin/..............................(at the every beginning is "dot colon dot colon dot colon")

my .bashrc file is :

# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

export PATH=.:$PATH

Do I need to do these steps as root?
 
Old 04-30-2003, 03:08 PM   #15
shadowbird
LQ Newbie
 
Registered: Apr 2003
Distribution: RedHat
Posts: 27

Rep: Reputation: 15
Well, that's an excessive number of .:'s at the beginning, but that shouldn't hurt anything. When you execute the commands:

blah

(replace "blah" with the name of your program)

Do you get any error message, or do you just get the command prompt again?

If you just get the command prompt, then your program IS being run, it's just not outputting anything - can we see the source code to your program?

If you're getting an error message when you execute "blah", then please let us know what the message is.

Thanks!
 
  


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
stock kernel 2.4.31 compiled with wrong gcc? uselpa Slackware 6 09-26-2005 02:35 AM
Wrong GCC version during compile? raid517 Linux - Software 4 09-14-2005 09:46 AM
Missing gcc or wrong version NoobVer.01 Fedora - Installation 1 08-19-2005 03:00 AM
LFS: gcc from wrong location??? 7.e.Q Linux From Scratch 0 07-08-2004 03:55 AM
mplayer - wrong gcc flags crashmeister Linux - Software 2 11-19-2002 07:25 AM


All times are GMT -5. The time now is 03:49 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration