Gcc Error Undefined Reference To Std Cout
here for a quick overview of undefined reference to `std::cout' clang the site Help Center Detailed answers to any questions
G++ Undefined Reference To Std::cout
you might have Meta Discuss the workings and policies of this site About
Undefined Reference To Std Basic_ostream Char
Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions
Clang Undefined Reference To Cout
Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up undefined reference to 'std::cout' up vote 35 std::ios_base::init::init() down vote favorite 7 Shall this be the example: #include using namespace std; int main() { cout << "Hola, moondo.\n"; } It throws the error: gcc -c main.cpp gcc -o edit main.o main.o: In function `main': main.cpp:(.text+0xa): undefined reference to `std::cout' main.cpp:(.text+0xf): undefined reference to `std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)' main.o: In function `__static_initialization_and_destruction_0(int,int)': main.cpp:(.text+0x3d): undefined reference to `std::ios_base::Init::Init()' main.cpp:(.text+0x4c): undefined reference to `std::ios_base::Init::~Init()' collect2: error: ld returned 1 exit status make: *** [qs] Error 1 Also, this example: #include int main() { std::cout<<"Hola, moondo.\n"; } throws the error: gcc -c main.cpp gcc -o edit main.o main.o: In function `main': main.cpp:(.text+0xa): undefined reference to `std::cout' main.cpp:(.text+0xf): undefined reference to `std::basic_ostream >& std::operator<<>(std::basic_ostream >&, char const*)' main.o: In function `__static_initialization_and_destruction_0(int,int)': main.cpp:(.text+0x3d): undefined reference to `std::ios_base::Init::Init()' main.cpp:(.text+0x4c):
Get Kubuntu Get Xubuntu Get Lubuntu Get UbuntuStudio Get Mythbuntu Get Edubuntu Get Ubuntu-GNOME Get UbuntuKylin Ubuntu Code of Conduct Ubuntu Wiki Community Wiki Other Support Launchpad Answers Ubuntu IRC Support AskUbuntu Official Documentation User Documentation Social difference between gcc and g++ Media Facebook Twitter Useful Links Distrowatch Bugs: Ubuntu PPAs: Ubuntu Web Upd8: Ubuntu OMG! Ubuntu undefined reference to std ostream operator int Ubuntu Insights Planet Ubuntu Activity Page Please read before SSO login Advanced Search Forum The Ubuntu Forum Community Ubuntu Specialised Support Development how to compile with g++ & Programming Programming Talk undefined reference to `std::cout' Having an Issue With Posting ? Do you want to help us debug the posting issues ? < is the place to report it, thanks ! Results 1 to http://stackoverflow.com/questions/28236870/undefined-reference-to-stdcout 8 of 8 Thread: undefined reference to `std::cout' Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode November 12th, 2006 #1 Blario View Profile View Forum Posts Private Message Just Give Me the Beans! Join Date Apr 2006 Beans 69 undefined reference to `std::cout' I've been compiling downloaded software for months now, with little problems. I went to compile some homework of mine https://ubuntuforums.org/showthread.php?t=297874 a second ago and got this error, Code: In function `main':test.cpp:(.text+0xa): undefined reference to `std::cout' , along with a following error for ever other similar reference. gcc -v outputs Code: gcc version 4.0.3 (Ubuntu 4.0.3-1ubuntu5) . The code of what I was trying to compile is ... Code: #include using namespace std; int main () { cout << "this was a test\n"; return 0; } I have the build-essential package installed, and even removed and re-installed it to see if that would help - no success. Why is it not finding header file iostream? Adv Reply November 12th, 2006 #2 Blario View Profile View Forum Posts Private Message Just Give Me the Beans! Join Date Apr 2006 Beans 69 Re: undefined reference to `std::cout' Answered my own question. I really didn't want to google myself first but I ended up doing it afterwards. I forgot that g++ is the command to be used to compile c++ code. You're supposed to use that. GCC is today the GNU C Collection, which includes gcc (the program) which is GNU C Compiler, and also includes g++, which is the program to be used to compile C++ code. Code: #dpkg -l g++ ||/ Name Version Description +++-==============-==============-=========================== ii g++ 4.0.3-1 The GNU C++ compiler Code: #dpkg -l gcc ||/ Name Version Description +++-==============-==============-==========
#include int ReadNumber() { using namespace std; cout << "Enter a http://www.cplusplus.com/forum/beginner/53731/ number: "; int x; cin >> x; return x; } void WriteAnswer(int x) { using namespace std; cout << "The answer is " << x << endl; } int main() { int x = ReadNumber(); int y = ReadNumber(); WriteAnswer(x+y); return 0; } Here is the error it undefined reference gives me: ~/Desktop/c++learning/quiz1> gcc -o num1 num1.cpp /tmp/ccmz5SRA.o: In function `ReadNumber(void)': num1.cpp:(.text+0x21): undefined reference to `cout' num1.cpp:(.text+0x29): undefined reference to `ostream::operator<<(char const *)' num1.cpp:(.text+0x39): undefined reference to `cin' num1.cpp:(.text+0x41): undefined reference to `istream::operator>>(int &)' /tmp/ccmz5SRA.o: In function `WriteAnswer(int)': num1.cpp:(.text+0x70): undefined reference to `endl(ostream &)' num1.cpp:(.text+0x8c): undefined reference to `cout' undefined reference to num1.cpp:(.text+0x94): undefined reference to `ostream::operator<<(char const *)' num1.cpp:(.text+0x9f): undefined reference to `ostream::operator<<(int)' collect2: ld returned 1 exit status if I use cout in the main method it doesn't give me errors, but if I use it in a different method it does. I am using gcc on Haiku OS. Oct 30, 2011 at 4:27am UTC Maese909 (131) Try getting rid of all the using namespace std; statements you have and put that statement just under the #include line. Oct 30, 2011 at 4:28am UTC shacktar (1187) That's weird. Did you try putting using namespace std; just under #include ? Did you also try doing std::cout and std::cin? And what about doing using std::cin; and using std::cout;? But, really, that code should compile. Oct 30, 2011 at 8:18pm UTC kidd106 (23) If I take off the using namespace std, I still get