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.
Simple enough right? Below is the output I get when I try to compille it. Please help me make since of what it is I need to do to produce C/C++ programs in a Linux Environment.
[wbsmith2@dhcppc1 programs]$ gcc -o hello hello.cpp
In file included from /usr/include/c++/3.2/backward/iostream.h:31,
from hello.cpp:1:
/usr/include/c++/3.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
/tmp/ccYveVmw.o: In function `main':
/tmp/ccYveVmw.o(.text+0x14): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/tmp/ccYveVmw.o(.text+0x21): undefined reference to `std::cout'
/tmp/ccYveVmw.o(.text+0x26): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccYveVmw.o(.text+0x2f): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccYveVmw.o: In function `__static_initialization_and_destruction_0(int, int)':
/tmp/ccYveVmw.o(.text+0x5c): undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccYveVmw.o: In function `__tcf_0':
/tmp/ccYveVmw.o(.text+0x8b): undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccYveVmw.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
[wbsmith2@dhcppc1 programs]$ ls
hello.cpp
trying using "#include <iostream>" without the .h, then you won't get the error message. As for why iostream.h is old or whats new in iostream, i couldn't tell you.
that "using namespace std;" is in my c++ book... but I never have to use it. I think it just tells the compiler to look in the "standard" place for the header files.
you're right on with the ./a.out . in the *nix systems, a "." means "current directory" and ".." means next directory up. so if you want to use an executable from your current directory, you do ./ . if you make another directory in there and change into it (cd), you can run that same binary with ../a.out. or, cd back up with cd .. ( or cd ../ to go along with what's stated above)
if you want to just be able to use your programs from anywhere on your system without having to type the full path, you need to put it in /bin, /usr/bin, or anything that gets spit out when you do "echo $PATH". you can also make a directory for only your programs and add that directory to your $PATH variable. open up the file ~/.bash_profile (files and directories w/ a "." in front of them are "hidden"... to see them all when you are in that directory do "ls -a").... also the "~/" means "home directory"... bash understands what you are talking about. this will be /root for the root user and /home/user for any other user.... ooh yeah.. back to $PATH.... open up your ~/.bash_profile, and you'll see a line like PATH=/bin:/usr/bin:, ect.. just put your personal program directory at the end and make sure each of the paths are separated by a colon.
well, have fun!
-Adam
p.s.- if you have gcc 3.1 (find out with gcc -v) there is a bug in <string.h>, so if you're planing on using that... you should upgrade to gcc-3.2
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.