Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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?
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:
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
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.