[완료]c++독학하고 있는데요... 코딩해보다가 궁금한게 생겼어요
글쓴이: wowns0224 / 작성시간: 일, 2011/12/18 - 3:33오후
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
typedef struct __Point
{
int xpos;
int ypos;
} Point;
Point& PntAdder(const Point &p1, const Point &p2)
{
Point* pnt = new Point;
pnt->xpos = p1.xpos + p2.xpos;
pnt->ypos = p1.ypos + p2.ypos;
return *pnt;
}
int main(void)
{
Point* Rpnt = new Point;
Rpnt->xpos = 10;
Rpnt->ypos = 20;
Point* Lpnt = new Point;
Lpnt->xpos = 20;
Lpnt->ypos = 40;
Point &ref = PntAdder(*Rpnt, *Lpnt);
cout << ref.xpos << "," << ref.ypos << endl;
return 0;
}이런 코드가 있어요..
컴퓨터 환경은
OS: Ubuntu11.10
컴파일러: gcc 4.6.1
이렇게 됩니다.
그런데
/tmp/ccewztRC.o: In function `PntAdder(__Point const&, __Point const&)': 02-3.cpp:(.text+0xe): undefined reference to `operator new(unsigned int)' /tmp/ccewztRC.o: In function `main': 02-3.cpp:(.text+0x51): undefined reference to `operator new(unsigned int)' 02-3.cpp:(.text+0x76): undefined reference to `operator new(unsigned int)' 02-3.cpp:(.text+0xbf): undefined reference to `std::cout' 02-3.cpp:(.text+0xc4): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)' 02-3.cpp:(.text+0xd4): 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*)' 02-3.cpp:(.text+0xe0): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)' 02-3.cpp:(.text+0xe8): 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> >&)' 02-3.cpp:(.text+0xf0): 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/ccewztRC.o: In function `__static_initialization_and_destruction_0(int, int)': 02-3.cpp:(.text+0x11b): undefined reference to `std::ios_base::Init::Init()' 02-3.cpp:(.text+0x120): undefined reference to `std::ios_base::Init::~Init()' collect2: ld returned 1 exit status
이런 오류들이 뜨더군요..
Windows7에서 VS2010가지고 컴파일할 땐 없었는데...
뭐가 문제일까요?
Forums:


gcc가 아니라 g++로 컴파일 해보세요.
gcc가 아니라 g++로 컴파일 해보세요.
표준라이브러리 링크가 안되는 걸로 봐서는 C++이 아닌 C로 컴파일 한듯하네요.
아 그랬었군요.....
g++로 컴파일을 해야했군요
해결되었습니다.
감사합니다.
댓글 달기