不能用gcc编译cpp
- mszjk
- 帖子: 94
- 注册时间: 2008-05-25 23:13
不能用gcc编译cpp
#include <iostream>
using namespace std ;
int main ()
{
cout << "haha" << endl ;
renturn 0 ;
}
用gcc编译的时候得到如下内容:/tmp/ccgd8lBO.o: In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
test.cpp:(.text+0xe): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
test.cpp:(.text+0x59): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
test.cpp:(.text+0x97): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
test.cpp:(.text+0xdf): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccgd8lBO.o: In function `main':
test.cpp:(.text+0x128): undefined reference to `std::cout'
test.cpp:(.text+0x12d): 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.cpp:(.text+0x135): 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.cpp:(.text+0x13d): 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/ccgd8lBO.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x16d): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccgd8lBO.o: In function `__tcf_0':
test.cpp:(.text+0x1ba): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccgd8lBO.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld 返回 1
不知道是怎么回事。好像是iostream的问题。可是在/usr/include/c++/4.2.3中明明存在iostream,并且可以正常预编译。
编译环境已经配置好了。
不知道是不是emacs的配置问题?[/img]
using namespace std ;
int main ()
{
cout << "haha" << endl ;
renturn 0 ;
}
用gcc编译的时候得到如下内容:/tmp/ccgd8lBO.o: In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
test.cpp:(.text+0xe): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
test.cpp:(.text+0x59): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
test.cpp:(.text+0x97): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
test.cpp:(.text+0xdf): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccgd8lBO.o: In function `main':
test.cpp:(.text+0x128): undefined reference to `std::cout'
test.cpp:(.text+0x12d): 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.cpp:(.text+0x135): 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.cpp:(.text+0x13d): 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/ccgd8lBO.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x16d): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccgd8lBO.o: In function `__tcf_0':
test.cpp:(.text+0x1ba): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccgd8lBO.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld 返回 1
不知道是怎么回事。好像是iostream的问题。可是在/usr/include/c++/4.2.3中明明存在iostream,并且可以正常预编译。
编译环境已经配置好了。
不知道是不是emacs的配置问题?[/img]
qq群45420595,欢迎加入,共同努力。
“上”或“下“,那得看你怎么看了。
“上”或“下“,那得看你怎么看了。
-
- 帖子: 972
- 注册时间: 2007-09-14 19:51
- mszjk
- 帖子: 94
- 注册时间: 2008-05-25 23:13
- mszjk
- 帖子: 94
- 注册时间: 2008-05-25 23:13
- mszjk
- 帖子: 94
- 注册时间: 2008-05-25 23:13
-
- 帖子: 9
- 注册时间: 2007-04-22 0:56
##To compile without using a makefile
# To compile an object file from a source file you could execute
# g++ -ansi -W -Wall -c filename.cc # produces filename.obj
# To compile an executable file from an object file, you would execute
# g++ -ansi -W -Wall filename.o # produces filename.exe
# To compile an executable file from a source file, you would execute
# g++ -ansi -W -Wall filename.cc # produces filename.exe
##
# To compile an object file from a source file you could execute
# g++ -ansi -W -Wall -c filename.cc # produces filename.obj
# To compile an executable file from an object file, you would execute
# g++ -ansi -W -Wall filename.o # produces filename.exe
# To compile an executable file from a source file, you would execute
# g++ -ansi -W -Wall filename.cc # produces filename.exe
##
-
- 帖子: 2841
- 注册时间: 2006-09-11 22:47
-
- 帖子: 38
- 注册时间: 2008-09-01 15:57
-
- 帖子: 8
- 注册时间: 2009-08-27 11:03
Re: 不能用gcc编译cpp
楼主没看清啊 仔细点
-
- 帖子: 6548
- 注册时间: 2008-10-31 22:12
- 系统: 践兔
- 联系:
- wangdu2002
- 帖子: 13284
- 注册时间: 2008-12-13 19:39
- 来自: 物华天宝人杰地灵