[완료]C++, 간단한 예제인데 컴파일이 안되요

gurumong의 이미지

C++을 공부하고 있습니다
처음으로 예제를 컴파일 해보았는데 안되네요 ㅜ.ㅜ
무엇이 문제일까요?

#include <iostream>
using namespace std;
int main(void)
{
    char ch;
    cout << "원하는 문자 하나를 입력하고 Enter 키를 누르십시오:\n";
    cin >> ch;
    cout << "감사합니다.";
    cout << "당신이 입력한 문자는 " << ch << " 입니다.\n";
    return 0;
}

C:\work>gcc listing3.4.cpp
C:\DOCUME~1\user\LOCALS~1\Temp/ccM9yDi3.o:listing3.4.cpp:(.text+0xd): undefined reference to `std::string::size() const'
C:\DOCUME~1\user\LOCALS~1\Temp/ccM9yDi3.o:listing3.4.cpp:(.text+0x60): undefined reference to `std::string::operator[](unsigned int) const'
C:\DOCUME~1\user\LOCALS~1\Temp/ccM9yDi3.o:listing3.4.cpp:(.text+0x9e): undefined reference to `std::string::operator[](unsigned int) const'
C:\DOCUME~1\user\LOCALS~1\Temp/ccM9yDi3.o:listing3.4.cpp:(.text+0xcc): undefined reference to `std::string::operator[](unsigned int) const'
C:\DOCUME~1\user\LOCALS~1\Temp/ccM9yDi3.o:listing3.4.cpp:(.text+0x133): undefined reference to `std::cout'
C:\DOCUME~1\user\LOCALS~1\Temp/ccM9yDi3.o:listing3.4.cpp:(.text+0x138): 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*)'
C:\DOCUME~1\user\LOCALS~1\Temp/ccM9yDi3.o:listing3.4.cpp:(.text+0x146): undefined reference to `std::cin'
C:\DOCUME~1\user\LOCALS~1\Temp/ccM9yDi3.o:listing3.4.cpp:(.text+0x14b): undefined reference to `std::basic_istream<char, std::char_traits<char> >& std::operator>><char, std::char_traits<char> >(std::basic_istream<char, std::char_traits<char> >&, char&)'
C:\DOCUME~1\user\LOCALS~1\Temp/ccM9yDi3.o:listing3.4.cpp:(.text+0x15a): undefined reference to `std::cout'
C:\DOCUME~1\user\LOCALS~1\Temp/ccM9yDi3.o:listing3.4.cpp:(.text+0x15f): 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*)'
C:\DOCUME~1\user\LOCALS~1\Temp/ccM9yDi3.o:listing3.4.cpp:(.text+0x16e): undefined reference to `std::cout'
C:\DOCUME~1\user\LOCALS~1\Temp/ccM9yDi3.o:listing3.4.cpp:(.text+0x173): 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*)'
C:\DOCUME~1\user\LOCALS~1\Temp/ccM9yDi3.o:listing3.4.cpp:(.text+0x185): 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)'
C:\DOCUME~1\user\LOCALS~1\Temp/ccM9yDi3.o:listing3.4.cpp:(.text+0x195): 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*)'
C:\DOCUME~1\user\LOCALS~1\Temp/ccM9yDi3.o:listing3.4.cpp:(.text+0x1bd): undefined reference to `std::ios_base::Init::Init()'
C:\DOCUME~1\user\LOCALS~1\Temp/ccM9yDi3.o:listing3.4.cpp:(.text+0x1d8): undefined reference to `std::ios_base::Init::~Init()'
collect2: ld returned 1 exit status

hongwoo의 이미지

g++ listing3.4.cpp

^^
-----------------------------
in the real-time scheduler !

-----------------------------
in the real-time scheduler !

pchero의 이미지

저는 뻘짓했었네요.ㅋ

에궁

iostream이 빠진줄 알았더니...;; 그게 아니라 g++이 아니라 gcc ;;;

---------------------------------
제일 왼쪽이 저입니다 :)

---------------------------------
제일 왼쪽이 저입니다 :)

gurumong의 이미지

두분 답변 감사합니다 ^^
g++ listing3.4.cpp로 하니까 컴파일이 되네요

그런데 원래 gcc가 소스파일의 확장자를 보고 c소스인지 c++소스인지 판단해서 컴파일을 해주는게 아닌가요?
뿌리는 오류메세지의 내용은 알수는 없지만;; 'std::cout'어쩌니 하는 내용이 포함되어있는걸로 봐서 c++ 컴파일러로 컴파일을 시도한거 같은데
아닌가요? ㅜ.ㅜ

fm100의 이미지

stdc++이 링크가 안되서 그렇습니다.

g++ listing3.4.cpp 는

gcc listing3.4.cpp -lstdc++ 과 동일합니다.
=================================================
Do the python !
=================================================

=================================================
Do the python !
=================================================

Fe.head의 이미지

make listing3.4

해도 됩니다.

-----------------------
과거를 알고 싶거든 오늘의 네 모습을 보아라. 그것이 과거의 너니라.
그리고 내일을 알고 싶으냐?
그러면 오늘의 너를 보아라. 그것이 바로 미래의 너니라.

고작 블로킹 하나, 고작 25점 중에 1점, 고작 부활동
"만약 그 순간이 온다면 그때가 네가 배구에 빠지는 순간이야"

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.