LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-09-2003, 08:47 PM   #16
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,986
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880

man gcc

-L = Path to libraries

I find it a bit odd that you have to point
the compiler to the includes, in the first
place, though, and believe there's some-
thing wrong with your installation.

Cheers,
Tink
 
Old 07-10-2003, 03:15 PM   #17
kbeaver
Member
 
Registered: Jul 2003
Location: Lakewood, CO
Distribution: SuSE 8.2
Posts: 41

Original Poster
Rep: Reputation: 15
I found an option that works.
gcc file.cpp -lstdc++

What does that mean?
 
Old 07-10-2003, 03:18 PM   #18
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,986
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
That means that you're using the C compiler
instead of the C++ one and tell it to link against
the stdc++ library :}

Cheers,
Tink
 
Old 07-11-2003, 02:35 AM   #19
captainstorm
Member
 
Registered: Jun 2003
Location: Oricola, Italy
Distribution: RH 9, so far
Posts: 261

Rep: Reputation: 30
?? Sorry but I am a little confused here. Do you mean you use the gcc to compile the code containing "cout<<....<<...."?

This error is also weird to me, since the code compiles well on my computer. I think probably you accidentally modified some settings of the system library or include file. like /etc/ld.so.conf

Qu Chen
 
Old 07-11-2003, 09:17 AM   #20
kbeaver
Member
 
Registered: Jul 2003
Location: Lakewood, CO
Distribution: SuSE 8.2
Posts: 41

Original Poster
Rep: Reputation: 15
I just installed Linux a week ago. I have not modified anything really. I just looked at that file, they are not where ALL of my libraries are. Should I add them?
 
Old 07-11-2003, 09:24 AM   #21
kbeaver
Member
 
Registered: Jul 2003
Location: Lakewood, CO
Distribution: SuSE 8.2
Posts: 41

Original Poster
Rep: Reputation: 15
THAT WAS IT! After I added where the includes lived (/usr/..../g++) the file compiled with out the -lstdc++ option (that is really lazy of me! I spend two days looking for a way not to type in eight characters every time I compile )

Thanks for all of your help guys
 
Old 07-11-2003, 09:49 AM   #22
TheLinuxDuck
Member
 
Registered: Sep 2002
Location: Tulsa, OK
Distribution: Slack, baby!
Posts: 349

Rep: Reputation: 33
Quote:
Originally posted by kbeaver
I spend two days looking for a way not to type in eight characters every time I compile
Actually, I think that is one of the mission statements in the programmers handbook. (=
 
Old 07-11-2003, 07:26 PM   #23
Mechanic
LQ Newbie
 
Registered: Jun 2003
Posts: 24

Rep: Reputation: 15
I'm having a similar problem but not having any luck. I'm trying to compile the "helloworld.cpp" program and getting the following error:

helloworld.cpp: In function `int main()':
helloworld.cpp:5: `cout' undeclared (first use this function)
helloworld.cpp:5: (Each undeclared identifier is reported only once for each function it appears in.)
helloworld.cpp:5: `endl' undeclared (first use this function)

The code is:

#include <iostream>

int main()
{
cout<<"Hello World!"<<endl;
return 0;
}

I tried the solutions that you guys tried (including 'gcc file.cpp -lstdc++) but they didn't work. I think my C++ libraries are in /usr/include/c++/3.2. The iostream lib is there. Any thoughts? Thanks.
 
Old 07-11-2003, 07:31 PM   #24
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 50
either prefix cout and endl with std:: or add the line

using namespace std;

before main
 
Old 07-11-2003, 11:23 PM   #25
Mechanic
LQ Newbie
 
Registered: Jun 2003
Posts: 24

Rep: Reputation: 15
Thanks Kev! The 'using namespace std;' worked. But tell me, why do you have to use that? Why is it not enough to use g++ and c++ libraries? Thanks again.
 
Old 07-12-2003, 01:30 AM   #26
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,986
Blog Entries: 11

Rep: Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880Reputation: 880
Because namespaces make sense,
and the new standard requires either
adding the namespace to the function,
or the "using namespace std" at the
beginning. The latter (even though more
convenient) is considered worse style.

Cheers,
Tink
 
Old 02-06-2004, 07:35 PM   #27
verdeboy2k
Member
 
Registered: Jan 2004
Location: /dev/random
Distribution: Gentoo amd64, CrunchBang amd64
Posts: 350

Rep: Reputation: 32
EDIT Will someone who can plz delete this, silly me didn't see the part about prefixing std:: before cout, etc. That fixed it. But still, why is the std:: part necessary, i have used gcc before and it didn't require this. /EDIT

i have had the same problem, i use g++ 3.2.3. the headers are
Code:
#include <iostream>

using namespace std;
BUT it still spouts forth about 30 error messages that even i can't understand.

Last edited by verdeboy2k; 02-06-2004 at 07:38 PM.
 
Old 02-06-2004, 08:02 PM   #28
lyle_s
Member
 
Registered: Jul 2003
Distribution: Slackware
Posts: 388

Rep: Reputation: 52
Quote:
Originally posted by kbeaver

: undefined reference to `endl(ostream&)'
I looks like you're using the "gcc" command to compile the program. You've got to use the "g++" command to compile a C++ program.

Lyle
 
  


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
Problems compiling a simple shell program yekrahs Programming 3 09-26-2005 12:07 PM
Compiling a simple C++ program for Windows Baix Programming 2 03-05-2005 07:17 PM
compiling simple c/c++ program but no good freeindy Programming 3 02-12-2005 11:38 AM
Compiling a simple Mesa/GLUT program Bojdom Linux - Software 2 02-02-2003 04:19 PM
Simple compiling question??? cameronknives Linux - General 5 02-10-2002 10:58 AM


All times are GMT -5. The time now is 05:38 AM.

Main Menu
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