LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 10-31-2013, 10:10 PM   #1
Djyou
LQ Newbie
 
Registered: Jun 2013
Distribution: Whatever works for the job.
Posts: 25

Rep: Reputation: Disabled
std::cout error


Okay so I'm rebuilding an old counting program of mine because I want to assemble a private header file(Some function I just want to be able to call whenever instead of having to keep them in some random file somewhere on my drive to copy paste whenever I need them. I'm trying at this moment to get std::cout to work so here be the code.

Code:
#include <iostream> //I think I need this for this program
#define infinite while( 1 < 2 )
int count = 0;

int main() {
	infinite{
		std::cout << count;
		count++;
	}
}
error is

Code:
/tmp/cc9iYJpZ.o: In function `main':
counter.cpp:(.text+0xd): undefined reference to `std::cout'
counter.cpp:(.text+0x12): undefined reference to `std::ostream::operator<<(int)'
/tmp/cc9iYJpZ.o: In function `__static_initialization_and_destruction_0(int, int)':
counter.cpp:(.text+0x4a): undefined reference to `std::ios_base::Init::Init()'
counter.cpp:(.text+0x59): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
What's the problem here? did I forget something somewhere it's been awhile since I've done cpp coding. At all.

--Djyou

Last edited by Djyou; 10-31-2013 at 10:12 PM.
 
Old 11-01-2013, 05:33 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

Did you try to compile it with gcc? Try g++ instead and it will work.
 
1 members found this post helpful.
Old 11-01-2013, 05:58 AM   #3
saopedrodaserra
Member
 
Registered: Sep 2010
Location: rio de janeiro
Distribution: slackware
Posts: 39

Rep: Reputation: 0
Smile namespace

int main(void)
{
return 0;
}

// the function main returns an integer, "int main()", so you must do this and i dont know whats going to be with the infinite loop and count++, i // think depends on the o.s. and the compiler. And try to do a good code. "KISS" rule, "keep it simple stupid".

Last edited by saopedrodaserra; 11-01-2013 at 06:12 AM.
 
Old 11-01-2013, 09:08 PM   #4
Djyou
LQ Newbie
 
Registered: Jun 2013
Distribution: Whatever works for the job.
Posts: 25

Original Poster
Rep: Reputation: Disabled
@Guttorm
Your solution worked. However why? I can't call the question answered until I know why it worked after such an seemingly minor change. Though I did mark your answer helpful.
 
Old 11-01-2013, 09:13 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by Djyou View Post
@Guttorm
Your solution worked. However why? I can't call the question answered until I know why it worked after such an seemingly minor change. Though I did mark your answer helpful.
Could this be it, from man gcc:

Code:
However, the use of gcc does not add the C++ library.  g++ is a program that calls GCC and treats .c, .h
and .i files as C++ source files instead of C source files unless -x is used, and automatically speci-
fies linking against the C++ library.  This program is also useful when precompiling a C header file
with a .h extension for use in C++ compilations.  On many systems, g++ is also installed with the name
c++.

Last edited by astrogeek; 11-01-2013 at 09:20 PM. Reason: Formatting...
 
1 members found this post helpful.
Old 11-01-2013, 10:14 PM   #6
Djyou
LQ Newbie
 
Registered: Jun 2013
Distribution: Whatever works for the job.
Posts: 25

Original Poster
Rep: Reputation: Disabled
Thanks Astro. Will mark as answered now.
 
  


Reply



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
std::cin/std::cout or cin/cout? shifter Programming 1 10-16-2013 01:24 PM
printf vs std::cout and std::ofstream grob115 Programming 2 01-16-2013 11:49 AM
C++ simple problem, doesn't recognize some std::cout itz2000 Programming 3 06-28-2007 08:18 PM
pblm with std::cout while compiling adilturbo Programming 7 06-12-2006 07:56 AM
`cout' undeclared in namespace `std' aw_wolfe Programming 1 04-30-2005 09:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:20 AM.

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
Open Source Consulting | Domain Registration