C++ 소스를 gcc와 g++로 컴파일 할 때의 차이
글쓴이: 송지석 / 작성시간: 목, 2003/05/22 - 5:03오후
C++ 파일을 리눅스에서는 cc 확장자로 사용하잖아요? 그 확장자로 하면 gcc에서 자동으로 c++ 파일로 알고 처리하는 것으로 알고 있는데요.
그런데 아주 간단한 헬로월드 테스트 프로그램이 gcc로는 컴파일이 안되는군요..
[root@sjs root]# cat c++test.cc #include <string> #include <iostream> using namespace std; int main() { string str("hello world"); cout << str << endl; return 0; }
이런 코드입니다.
Quote:
[root@sjs root]# g++ c++test.cc
이렇게하면 잘 컴파일 되는데,
Quote:
[root@sjs root]# gcc c++test.cc
/tmp/ccmjz3Ou.o: In function `main':
/tmp/ccmjz3Ou.o(.text+0x1c): undefined reference to `std::allocator<char>::allocator[in-charge]()'
/tmp/ccmjz3Ou.o(.text+0x31): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string[in-charge](char const*, std::allocator<char> const&)'
/tmp/ccmjz3Ou.o(.text+0x48): undefined reference to `std::allocator<char>::~allocator [in-charge]()'
/tmp/ccmjz3Ou.o(.text+0x65): undefined reference to `std::allocator<char>::~allocator [in-charge]()'
/tmp/ccmjz3Ou.o(.text+0x70): 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> >&)'
/tmp/ccmjz3Ou.o(.text+0x7c): undefined reference to `std::cout'
/tmp/ccmjz3Ou.o(.text+0x81): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/ccmjz3Ou.o(.text+0x8a): 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/ccmjz3Ou.o(.text+0x99): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string [in-charge]()'
/tmp/ccmjz3Ou.o(.text+0xb0): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string [in-charge]()'
/tmp/ccmjz3Ou.o: In function `__static_initialization_and_destruction_0(int, int)':
/tmp/ccmjz3Ou.o(.text+0xee): undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccmjz3Ou.o: In function `__tcf_0':
/tmp/ccmjz3Ou.o(.text+0x11d): undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccmjz3Ou.o(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
이렇게 gcc로 하면 링커 에러가 난답니다. 음..
그렇다면 gcc로 컴파일 할 때는 링커 옵션으로 뭔가를 줘야만 하는 것인가요? 아님 g++로 컴파일 해야 할까요?
Forums:
g++로 하십시요.
gcc - cc1
g++ - cc1plus
의 관계일껍니다.
[url]http://bbs.kldp.org/viewtopic.php?t
http://bbs.kldp.org/viewtopic.php?t=19547
를 참고하세요.
아 그렇군요. stdc++ 기억하고 있었는데 왜 전혀 생각이 안난것인지.
아 그렇군요. stdc++ 기억하고 있었는데 왜 전혀 생각이 안난것인지..
답변 감사합니다.
rommance.net
이기야
이기야
14년 전 글에 답글 달지 말아라 이기야
14년 전 글에 답글 달지 말아라 이기야
컴파일러와 링커의 차이점을 알고 계십니까?
컴파일러와 링커의 차이점을 알고 계십니까?
댓글 달기