這是我test.cpp
:編譯C++代碼時出錯?
#include <iostream.h>
class C {
public:
C();
~C();
};
int main()
{
C obj;
return 0;
}
當我編譯使用命令g++ test.cpp
它,我得到這個錯誤信息:
In file included from /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/backward/iostream.h:31, from test.cpp:1: /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wno-deprecated. /cygdrive/c/Users/aswinik_sattaluri/AppData/Local/Temp/ccoYkiAS.o:test.cpp:(.text+0x131): undefined reference to `C::C()' /cygdrive/c/Users/aswinik_sattaluri/AppData/Local/Temp/ccoYkiAS.o:test.cpp:(.text+0x13c): undefined reference to `C::~C()' collect2: ld returned 1 exit status
與gcc test.cpp
編譯給出類似的消息,甚至更多:
In file included from /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/backward/iostream.h:31, from test.cpp:1: /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wno-deprecated. /cygdrive/c/Users/aswinik_sattaluri/AppData/Local/Temp/cc3ntGx0.o:test.cpp:(.text+0xd): undefined reference to `std::basic_string, std::allocator >::size() const' /cygdrive/c/Users/aswinik_sattaluri/AppData/Local/Temp/cc3ntGx0.o:test.cpp:(.text+0x60): undefined reference to `std::basic_string, std::allocator >::operator[](unsigned int) const' /cygdrive/c/Users/aswinik_sattaluri/AppData/Local/Temp/cc3ntGx0.o:test.cpp:(.text+0x9f): undefined reference to `std::basic_string, std::allocator >::operator[](unsigned int) const' /cygdrive/c/Users/aswinik_sattaluri/AppData/Local/Temp/cc3ntGx0.o:test.cpp:(.text+0xce): undefined reference to `std::basic_string, std::allocator >::operator[](unsigned int) const' /cygdrive/c/Users/aswinik_sattaluri/AppData/Local/Temp/cc3ntGx0.o:test.cpp:(.text+0x131): undefined reference to `C::C()' /cygdrive/c/Users/aswinik_sattaluri/AppData/Local/Temp/cc3ntGx0.o:test.cpp:(.text+0x13c): undefined reference to `C::~C()' /cygdrive/c/Users/aswinik_sattaluri/AppData/Local/Temp/cc3ntGx0.o:test.cpp:(.text+0x165): undefined reference to `std::ios_base::Init::Init()' /cygdrive/c/Users/aswinik_sattaluri/AppData/Local/Temp/cc3ntGx0.o:test.cpp:(.text+0x180): undefined reference to `std::ios_base::Init::~Init()' collect2: ld returned 1 exit status
請注意,我沒有設置LD_LIBRARY_PATH
:
bash-3.2$ echo $LD_LIBRARY_PATH bash-3.2$
正確格式化您的代碼(請使用下次預覽!)。仍然 - 問題是什麼? – 2010-03-02 07:39:15
所有標準的C++頭文件都沒有擴展名。 – GManNickG 2010-03-02 08:04:41