Installed Cygwin and can't compile

BinaryCleric

Limp Gawd
Joined
May 25, 2005
Messages
193
I just installed Cygwin and gcc on my computer and everytime I compile a C++ program with something simple like IOSTREAM or FSTREAM I get this error.

[OUTPUT]
/cygdrive/c/DOCUME~1/Cleric/LOCALS~1/Temp/ccvXrMm2.o:test.cpp: (.text+0xd): undef
ined reference to `std::basic_string<char, std::char_traits<char>, std::allocato
r<char> >::size() const'
/cygdrive/c/DOCUME~1/Cleric/LOCALS~1/Temp/ccvXrMm2.o:test.cpp: (.text+0x60): unde
fined reference to `std::basic_string<char, std::char_traits<char>, std::allocat
or<char> >:: operator[](unsigned int) const'
/cygdrive/c/DOCUME~1/Cleric/LOCALS~1/Temp/ccvXrMm2.o:test.cpp: (.text+0x9f): unde
fined reference to `std::basic_string<char, std::char_traits<char>, std::allocat
or<char> >:: operator[](unsigned int) const'
/cygdrive/c/DOCUME~1/Cleric/LOCALS~1/Temp/ccvXrMm2.o:test.cpp: (.text+0xce): unde
fined reference to `std::basic_string<char, std::char_traits<char>, std::allocat
or<char> >:: operator[](unsigned int) const'
/cygdrive/c/DOCUME~1/Cleric/LOCALS~1/Temp/ccvXrMm2.o:test.cpp: (.text+0x14f): und
efined reference to `std::ios_base::Init::Init()'
/cygdrive/c/DOCUME~1/Cleric/LOCALS~1/Temp/ccvXrMm2.o:test.cpp: (.text+0x16a): und
efined reference to `std::ios_base::Init::~Init()'
collect2: ld returned 1 exit status
[/OUTPUT]

I am new to Gygwin but not to Unix, and I have no idea what is going on.
 
Could you post the original code so that we can see what could be the problem? It looks like you haven't declared your variables correctly, or you have something else messing them up.
 
Code:
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
  cout << "test";

  return 0;
}
 
DeenlyFan1337 said:
Could you post the original code so that we can see what could be the problem? It looks like you haven't declared your variables correctly, or you have something else messing them up.

That's not my read. You'll note that his source code declares no variables. The compiler has run successfully; these messages are coming from the linker.

A corrupt or a missing library file would be my guess; libraries out of order on the command line, mismatched libraries for the link options, and so on.
 
Lord of Shadows said:
You might have better luck with a c++ compiler, like g++ ;o)
Har! Good point. But why does this get past the compiler?

Code:
collect2: ld returned 1 exit status

Or is it that the messages are coming from the compiler, and the linker still tries to run, but can't, because the compiler didn't emit an object file?

What does "(.text+0xd):" mean in the error messages? Why would there be a binary offset from a section if there wasn't an object?
 
g++ uses gcc, something different with how it links to who knows what but I'll see if I can just get an object file and link things myself later.

Edit: I cant seem to find anything in the man pages / online with what g++ passes to the linker. But you can get the object file easy enough by surpressing gcc's linking stage with the -c option.
 
gcc and g++ will both compile cpp code, but you need g++ to link it correctly (or gcc with the proper command line switches, god knows what those are).

Also, might i recommend mingw instead of the cygwin gcc? cygwins gcc requires cygwin1.dll for it's compiles, whereas mingw is an actual windows port of gcc, runs native on windows without any compatibility layers necessary. Still runs fine inside of cygwin (as do all programs), but this way if you compile something, it compiles and runs without cygwin for other users.

My current setup is mingw + cygwin + windows gvim. Get all of the goodies of cygwin, perl/grep/etc, all of the power of gvim, and 100% windows code with no compatibility layer.
 
Back
Top