Reputation: 303
I recently decided to start writing standards-compliant C++ instead of using Turbo-C++ and so I downloaded cygwin on windows 7 and installed g++. I tried to run a hello world program:
#include<iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
and typed this in cygwin:
g++ test.cpp -o test
g++ test
Hoping I'd done alright, I pressed enter to find my heart broken by this giant wall of incomprehensible text:
$ g++ test.exe
test.exe: In function `mainCRTStartup':
/usr/src/debug/cygwin-1.7.27-2/winsup/cygwin/crt0.c:23: multiple definition of `mainCRTStartup'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/../../../../lib/crt0.o:/usr/src/debug/cygwin-1.7.27-2/winsup/cygwin/crt0.c:23: first defined here
test.exe: In function `mainCRTStartup':
/usr/src/debug/cygwin-1.7.27-2/winsup/cygwin/crt0.c:23: multiple definition of `WinMainCRTStartup'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/../../../../lib/crt0.o:/usr/src/debug/cygwin-1.7.27-2/winsup/cygwin/crt0.c:23: first defined here
test.exe:cygming-crtbegin.c:(.text+0x60): multiple definition of `__gcc_register_frame'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/crtbegin.o:cygming-crtbegin.c:(.text+0x10): first defined here
test.exe:cygming-crtbegin.c:(.text+0xc0): multiple definition of `__gcc_deregister_frame'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/crtbegin.o:cygming-crtbegin.c:(.text+0x70): first defined here
test.exe:crt0.c:(.text+0x50): multiple definition of `.weak._Jv_RegisterClasses.__gcc_register_frame'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/crtbegin.o:cygming-crtbegin.c:(.text+0x0): first defined here
test.exe:cygming-crtend.c:(.idata+0x178): multiple definition of `__imp__ZSt4cout'
test.exe:cygming-crtend.c:(.idata+0x178): first defined here
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/crtbegin.o:cygming-crtbegin.c:(.text+0x35): undefined reference to `_Jv_RegisterClasses'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/crtbegin.o:cygming-crtbegin.c:(.text+0x35): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `_Jv_RegisterClasses'
/usr/lib/gcc/x86_64-pc-cygwin/4.8.2/../../../../x86_64-pc-cygwin/bin/ld: /usr/lib/gcc/x86_64-pc-cygwin/4.8.2/crtbegin.o: bad reloc address 0x0 in section `.pdata'
collect2: error: ld returned 1 exit status
Could somebody please take a look at this and tell me what I'm doing wrong?
Upvotes: 0
Views: 2211
Reputation: 503
No need for the g++ test
command
the command g++ test.cpp -o test
will compile and link your code. you can run it using ./test.exe
Upvotes: 3