Kind of a newbi question about gcc (I think)
|
|
Venaqua
Junior Member
|
19. June 2008 @ 20:04 |
Link to this message
|
So I switch from Windows to Ubuntu about a month or two ago and I thought it would make sense to learn some programing so I'm trying to learn C++ and, of course my first program is a Hello World one named Hello.cpp. The book I'm learning from says to type at the command prompt ~$cc Hello.cpp to compile it in MS-DOS.
So what I need to know is, for Linux would I type ~$gcc Hello.cpp. If not then what should I type and if so then why does this happen.
In file included from /usr/include/c++/4.2/backward/iostream.h:31,
from Hello.cpp:1:
/usr/include/c++/4.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 <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
/tmp/ccsOXpwT.o: In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
Hello.cpp:(.text+0xe): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
Hello.cpp:(.text+0x59): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
Hello.cpp:(.text+0x97): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
Hello.cpp:(.text+0xdf): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccsOXpwT.o: In function `main':
Hello.cpp:(.text+0x128): undefined reference to `std::cout'
Hello.cpp:(.text+0x12d): 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/ccsOXpwT.o: In function `__static_initialization_and_destruction_0(int, int)':
Hello.cpp:(.text+0x15d): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccsOXpwT.o: In function `__tcf_0':
Hello.cpp:(.text+0x1aa): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccsOXpwT.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
After this happens I don't get a program or any thing else.Could somebody please tell me what this means.
Also heres the program in case I made A mistake there (tho I don't think I did).
#include <iostream.h>
int main ()
{
cout<<"Hello, World\n";
return 0;
}
If somebody could help me I would really appreciate.
|
Advertisement
|
|
|
varnull
Suspended permanently
|
19. June 2008 @ 21:24 |
Link to this message
|
Not the kind of help you will find on this site.. Think I'm about the only C programmer of any kind here ;) And it's years ago now.. haven't done any in ages.
so.. you are working through Object-Oriented Programming in C++
by Nicolai M. Josuttis eh? Not a bad book.. a little thin on the actual explanation.
#include <iostream> // declarations for I/O
int main() // main function main()
{
/* print `Hello, World!' on standard output channel std::cout
* followed by an endline (std::endl)
*/
std::cout << "Hello, World!" << std::endl;
}
You are using an old/deprecated header.. Quote: #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 <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
i.e <iostream.h> where you should be using <iostream> and from there on it all goes wrong... you should be able to work out from my code example you aren't actually generating anything, or outputting it to anywhere.
When you have managed to actually compile it call the resulting file hello.c and you should be able to run it by making it executable and calling it by name XD
For the compiler commands try the man page for whatever C compiler you are using. This should help ;) http://www.cyberciti.biz/faq/compiling-c...xecutable-file/
Lesson 1.. read the output from errors carefully ;) Have fun
This message has been edited since posting. Last time this message was edited on 19. June 2008 @ 21:32
|
Venaqua
Junior Member
|
20. June 2008 @ 01:07 |
Link to this message
|
Thanks but I'm not reading Object-Oriented Programming in C++ by Nicolai M. Josuttis.
I'm reading Teach Yourself C++ by Richard Riley.I copied the code out of that book to make sure my compiler worked. But apparently the code doesn't work. The copyright date on the book is 1999. Should I get A newer book.
Anyways, I tried your code and got this
/tmp/ccpC8w57.o: In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
Hello.cpp:(.text+0xe): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
Hello.cpp:(.text+0x59): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
Hello.cpp:(.text+0x97): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
Hello.cpp:(.text+0xdf): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccpC8w57.o: In function `main':
Hello.cpp:(.text+0x128): undefined reference to `std::cout'
Hello.cpp:(.text+0x12d): 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*)'
Hello.cpp:(.text+0x135): 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> >&)'
Hello.cpp:(.text+0x13d): 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/ccpC8w57.o: In function `__static_initialization_and_destruction_0(int, int)':
Hello.cpp:(.text+0x16d): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccpC8w57.o: In function `__tcf_0':
Hello.cpp:(.text+0x1ba): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccpC8w57.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
I don't know what that means. But I followed the link you gave and got it to work. But do you think my book is to old to learn out of.
|
varnull
Suspended permanently
|
20. June 2008 @ 05:23 |
Link to this message
|
That is a long time ago. It's about the time I last did any C coding ;)
Obviously the compilers have moved on from then, but in theory it should all work.
I think you really need up to date and relevant help... and I can't think of any nicer people to help you out than at http://www.jharbour.com/forum
Otherwise.. just read and read. The linux compiler documentation is huge, and doesn't always follow what you will find in books which always seem to have been written for windows/dos based compilers these days.
Good Luck..
|
OzMick
Suspended permanently
|
20. June 2008 @ 07:27 |
Link to this message
|
I can't help much either. Always preferred pure C myself, never bothered with remembering much while learning C++. In C at least the following works, but being C probably means dick to you.
#include <stdio.h>
int main (int argc, char** argv) {
printf("Hello world\n");
return 0;
}
There are loads of tutorials on the net, you should be able to find some good references without too much trouble. The language shouldn't have changed too significantly in the last 10 years, but could well have. C at least has such a small command set that 20 year old K&R ANSI C textbooks are still perfectly good.
|
varnull
Suspended permanently
|
20. June 2008 @ 13:37 |
Link to this message
|
Went playing with a pure unix system for work today.... I think you are lacking some of the C dev libs, which is why all the errors.
Ubuntu is sorely lacking in build/compile tools.. which I forgot all about. Try installing the debian build-essentials package and trying again ;)
|
OzMick
Suspended permanently
|
20. June 2008 @ 16:51 |
Link to this message
|
Varnull is probably right, Ubuntu is pretty useless in that respect. I remember the nightmare I went through to compile my network card driver so that I could just connect to the net a year or so ago. They stick you in a really dumb catch 22 - to compile anything you need to download libraries, but to download libraries I needed to be able to compile.
I think the live CD does have the required packages activated though, so you can build things before rebooting into your system and just transfer it across on a memory stick. But then you run into the same problem a few months later when the next kernel update rolls around and you haven't got the development packages installed...
|
Venaqua
Junior Member
|
20. June 2008 @ 17:49 |
Link to this message
|
Wait I'm a little confused. Should I use an Ubuntu live cd and but the build-essential package on usb stick. Or should I get a Debian live cd and then put their build-essential package on a usb stick. Or is there some were I can download the package.
Thanks for being so helpful guys.
|
OzMick
Suspended permanently
|
20. June 2008 @ 17:57 |
Link to this message
|
No, I was just telling a story of my experience with Ubuntu. Just use synaptic to install that package into your existing Ubuntu install and (hopefully) it will all work.
Sorry for any confusion there, your situation is just another example of why people don't tend to stay using Ubuntu for too long - it is easy for noobs to get started on, but the moment you want to do anything meaningful beyond just installing and using provided packages you seem to have to fight 10x harder than you would on any other distro.
|
OzMick
Suspended permanently
|
20. June 2008 @ 18:02 |
Link to this message
|
Just got the same messages when using the same source. Try using g++ instead of gcc...
Sure does pay to google, "c++ hello world linux" makes the solution a giveaway.
Edited because I probably sounded like an ass.
This message has been edited since posting. Last time this message was edited on 20. June 2008 @ 18:09
|
varnull
Suspended permanently
|
20. June 2008 @ 18:12 |
Link to this message
|
Oops **blushes**.. missed that one. i use a different compiler in a development environment separated from the main os (because I build platform independent IF I ever need to actually build anything so I can swap it around different machines)
I'm a bit distracted today.. lots going on around me.
This message has been edited since posting. Last time this message was edited on 20. June 2008 @ 18:13
|
Venaqua
Junior Member
|
21. June 2008 @ 00:03 |
Link to this message
|
Quote: Sure does pay to google, "c++ hello world linux" makes the solution a giveaway.
Edited because I probably sounded like an ass.
lol you did kind of sound like an ass .
I had the build-essentials package installed before I started. Should I try to find a debian build-essentials package and install that.
Also I tried using g++ instead gcc and it pretty much worked except that I had to add namespace std; to the code. Is that kind of new thing.
|
Brookscbg
Suspended permanently
|
25. June 2008 @ 08:43 |
Link to this message
|
Linux is not a user friendly OS at all but it's very often used in oop oriented languages.
|
varnull
Suspended permanently
|
25. June 2008 @ 12:52 |
Link to this message
|
Don't know where you get the idea it isn't user friendly.. It's the M$ stuff that is designed to lock the user out, not the open source OS.
Now about this compile error.. Better to look at the man page for the g++ compiler that is specific to your system. Every release has different requirements. I have a feeling there are still some dependencies missing.. such as g++-dev and quite possibly the linux-kernal-headers.
That is the kind of problem you can get when you are trying to build what is effectively alien code against your normal system libraries.
Maybe a good read of the LFS guides and homepage will solve all the problems and show you how to create a safe, and system independent build environment.
This message has been edited since posting. Last time this message was edited on 25. June 2008 @ 12:54
|
OzMick
Suspended permanently
|
25. June 2008 @ 14:49 |
Link to this message
|
Originally posted by Brookscbg: Linux is not a user friendly OS at all but it's very often used in oop oriented languages.
Have you actually used Linux or are you just spouting the same uninformed crap that MS shills have been for years? If you're just trolling, go back under your bridge or you'll be put there by one of the moderators.
|
Moderator
|
25. June 2008 @ 15:06 |
Link to this message
|
Originally posted by Brookscbg: Linux is not a user friendly OS at all but it's very often used in oop oriented languages.
These days it is actually very user friendly. And i'll ask you in a friendly manner to remove that link from your signature...
Main PC ~ Intel C2Q Q6600 (G0 Stepping)/Gigabyte GA-EP45-DS3/2GB Crucial Ballistix PC2-8500/Zalman CNPS9700/Antec 900/Corsair HX 620W
Network ~ DD-WRT ~ 2node WDS-WPA2/AES ~ Buffalo WHR-G54S. 3node WPA2/AES ~ WRT54GS v6 (inc. WEP BSSID), WRT54G v2, WRT54G2 v1. *** Forum Rules ***
|
varnull
Suspended permanently
|
25. June 2008 @ 17:55 |
Link to this message
|
Under the bridge indeed.. I like that image ;)
"I went with Fista down under the bridge.. I went in a child, and came out a sore fool" hahahaha.
FYI.. the bloody n00buntu repositories are broken again!! (and broken so well that poor Grace had a brainstorm, segfaulted and totally corrupted the /var/lib/dpkg/status file... which believe, you never ever want to have to edit manually.. all 32,000 lines of it.)
Lesson learned.. on n00b don't ever apt-get dist-upgrade without backing that damn file up somewhere else first.
I have put some dents in the walls of the house this evening.. and probably in my head as well..grrrrr.. arch here we come.
This message has been edited since posting. Last time this message was edited on 25. June 2008 @ 18:00
|
OzMick
Suspended permanently
|
26. June 2008 @ 03:08 |
Link to this message
|
If you're giving Arch a crack, a new base install disc was released just the other day. Doesn't mean too much if you're doing an FTP install (recommended), but there have been a couple of rearrangements to the repository categories over the past 6 months and it is running the latest kernel on the disc at least, so no reason not to use the latest.
Same rules as "emerge -U world" apply to "pacman -Syu". I think the best thing to do is either sync every week or never, you'd know the drill from Gentoo/Sabayon.
It isn't an option by default, but a few people link /var/cache/pacman/pkg to a separate partition, that way you can share downloaded packages between machines nicely or not lose them if you manage to obliterate your root partition.
|
varnull
Suspended permanently
|
26. June 2008 @ 12:54 |
Link to this message
|
Cheers for that... I will give it a go later, or over the weekend. I just needed it up and running last night to finish a rush job, so it ended up being lenny ;)
|
Member
|
27. June 2008 @ 19:16 |
Link to this message
|
Nowt wrong with lenny, runs on my main box as sweet as a dream. I will use it when i get round to building a home server (too much going on to sort out the finer points of that yet i.e. getting hdd's).
|
Advertisement
|
|
|
Venaqua
Junior Member
|
1. July 2008 @ 16:58 |
Link to this message
|
Should I be able to get these dependencies in synaptic or should I look somewhere else. I tried searching G++ in synaptic but I didn't really know if any of the stuff was useful or not. All the stuff that was not installed looked like older versions of stuff I already have installed.
I also tried reading the man page for G++. I haven't found any thing to help yet but I'll keep reading.
|