Tuesday, July 28, 2009

Can not compile C++ programs using GCC under Cygwin.?

I tried compiling a simple HelloWorld program using GCC





C++ code :


-----


#include %26lt;iostream%26gt;


//using namespace std;


int main(){


cout%26lt;%26lt;"Hello World!!";


return 0;


}


----





Error generated:





hello.cpp: In function `int main()':


hello.cpp:4: error: `cout' undeclared (first use this function)


hello.cpp:4: error: (Each undeclared identifier is reported only once for each function it appears in.)








I compiled this program using microsoft's viual studio compiler and there was no error as long I had uncommented "using namespace std;"





Under gcc, uncomenting "using namespace std;" leads to these errors





-------


/cygdrive/c/DOCUME~1/HP/LOCALS~1/Temp/... undefined reference to `std::basic_string%26lt;char, std::char_traits%26lt;char%26gt;, std::allocator%26lt;char%26gt; %26gt;::size() const'


/cygdrive/c/DOCUME~1/HP/LOCALS~1/Temp/... undefined reference to `std::basic_string%26lt;char, std::char_tra %26lt;TRUNCATED ERROR%26gt;

Can not compile C++ programs using GCC under Cygwin.?
Make sure you're compiling with "g++" as opposed to "gcc" -- sometimes it makes a difference.


No comments:

Post a Comment