Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
534 views
in Technique[技术] by (71.8m points)

cout - Very simple program not working in c++?

I can't figure out why this isn't working...

I am working in Linux

g++ doesn't do anything

gcc prints the following:

/tmp/ccyg7NDd.o: In function `main':
test.cc:(.text+0x14): undefined reference to `std::cout'
test.cc:(.text+0x19): 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*)'
test.cc:(.text+0x21): 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> >&)'
test.cc:(.text+0x29): 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/ccyg7NDd.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cc:(.text+0x51): undefined reference to `std::ios_base::Init::Init()'
test.cc:(.text+0x56): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccyg7NDd.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

Code:

#include<iostream>
#include<stdio.h>

int main(){

std::cout<<"test "<<std::endl;
return 0;

};
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
gcc main.cpp -lstdc++

or

g++ main.cpp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...