g++ libcygwin.a has an undefined reference

Jani tiainen redetin@luukku.com
Tue May 18 16:40:00 GMT 2004


Please, avoid top postings, this is hard to reply...

Christian Rudiger wrote:
> Hello Al,
> 
> thank you, it worked.
> i putted one at the end of the program just writing :
> 
> }; // end of class
> int main(){}
> 
> why does that work? I think thats strange.

Strange? Every program needs starting point. For standard C(++) program 
it's called "main", usually in form "int main(int argc, char *argv[])".

There is of course exceptions. Windows programs use "WinMain" or DLL's 
use "DllMain" instead of plain "main".

Your example really need to instantiate class tryit and call instance 
method main before it really works.

> Regards Christian Rudiger
> 
> Al Slater wrote:
> 
>> Try putting a main function in the program!
>>
>> Regards
>>
>> Al
>>
>>
>>> -----Original Message-----
>>> From: cygwin-owner@cygwin.com [mailto:cygwin-owner@cygwin.com] On 
>>> Behalf Of Christian Rudiger
>>> Sent: 18 May 2004 11:09
>>> To: cygwin@cygwin.com
>>> Subject: g++ libcygwin.a has an undefined reference
>>>
>>>
>>> Hello there,
>>>
>>> i think the following problem has to do with cygwin, cause 
>>> libcygwin.a has an undefined reference.
>>> I get the error message when compiling my little testprogram. The 
>>> Programm and complete compiler messages follow:
>>>
>>> *************************************************************
>>>
>>> // reading a text file
>>> #include <iostream.h>
>>> #include <fstream.h>
>>> #include <stdlib.h>
>>> #include <string.h>
>>>
>>> using namespace std;
>>>
>>> class tryit {
>>>
>>>   char *FILE_POSTFIX;// = new "myfile.txt"; <- ausserhalb nicht möglich
>>>   string posti;
>>> public:
>>>   int main (int argc, char** argv) {
>>>
>>>     FILE_POSTFIX = new char[10]; //"Nodes.txt"; <- erst allocieren 
>>> dann zuweisen !
>>>     FILE_POSTFIX = "NODES.txt";
>>>     char *filename = FILE_POSTFIX;
>>>     char *output;
>>>     ifstream in (filename) ;
>>>     while (in){
>>>     in >> output ;
>>>     cout << output << endl;
>>>     return 0;
>>>       }
>>>   }
>>> };
>>>
>>> *************************************************************
>>>
>>> g++ -v -Wall -Wno-deprecated tryme.cpp -o testthings.exe
>>> Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/specs
>>> Configured with: /GCC/gcc-3.3.1-3/configure --with-gcc --with-gnu-ld 
>>> --with-gnu-as --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc 
>>> --libdir=/usr/lib --libexecdir=/usr/sbin --mandir=/usr/share/man 
>>> --infodir=/usr/share/info 
>>> --enable-languages=c,ada,c++,f77,pascal,java,objc --enable-libgcj 
>>> --enable-threads=posix --with-system-zlib --enable-nls 
>>> --without-included-gettext --enable-interpreter 
>>> --enable-sjlj-exceptions --disable-version-specific-runtime-libs 
>>> --enable-shared --disable-win32-registry --enable-java-gc=boehm 
>>> --disable-hash-synchronization --verbose --target=i686-pc-cygwin 
>>> --host=i686-pc-cygwin --build=i686-pc-cygwin
>>> Thread model: posix
>>> gcc version 3.3.1 (cygming special)
>>>  /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/cc1plus.exe -quiet -v 
>>> -D__GNUC__=3 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=1 
>>> -D__CYGWIN32__ -D__CYGWIN__ -Dunix -D__unix__ -D__unix -idirafter 
>>> /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/../../../../include/w32api 
>>> -idirafter 
>>> /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/../../../../i686-pc-cygw
>>
>>
>> in/lib/../../include/w32api
>>
>>> tryme.cpp -D__GNUG__=3 -quiet -dumpbase tryme.cpp -auxbase tryme 
>>> -Wall -Wno-deprecated -version -o /cygdrive/d/TMP/cc55YaOO.s
>>> GNU C++ version 3.3.1 (cygming special) (i686-pc-cygwin)
>>>     compiled by GNU C version 3.3.1 (cygming special).
>>> GGC heuristics: --param ggc-min-expand=47 --param 
>>> ggc-min-heapsize=32700 ignoring nonexistent directory 
>>> "/usr/local/include" ignoring nonexistent directory 
>>> "/usr/i686-pc-cygwin/include" ignoring duplicate directory 
>>> "/usr/i686-pc-cygwin/lib/../../include/w32api"
>>> #include "..." search starts here:
>>> #include <...> search starts here:
>>>  /usr/include/c++/3.3.1
>>>  /usr/include/c++/3.3.1/i686-pc-cygwin
>>>  /usr/include/c++/3.3.1/backward
>>>  /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/include
>>>  /usr/include
>>>  /usr/include/w32api
>>> End of search list.
>>>
>>> /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/../../../../i686-pc-cygw
>>
>>
>> in/bin/as.exe
>>
>>> --traditional-format -o /cygdrive/d/TMP/ccbPwKZW.o 
>>> /cygdrive/d/TMP/cc55YaOO.s
>>>  /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/collect2.exe -Bdynamic 
>>> --dll-search-prefix=cyg -o testthings.exe 
>>> /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/../../../crt0.o 
>>> /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/crtbegin.o 
>>> -L/usr/lib/gcc-lib/i686-pc-cygwin/3.3.1 
>>> -L/usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/../../.. 
>>> /cygdrive/d/TMP/ccbPwKZW.o -lstdc++ -lgcc -lcygwin -luser32 
>>> -lkernel32 -ladvapi32 -lshell32 -lgcc 
>>> /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/crtend.o
>>> /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/../../../libcygwin.a(lib
>>> cmain.o)(.text+0x7c): undefined reference to `_WinMain@16'
>>> collect2: ld returned 1 exit status
>>> make: *** [testthings.exe] Error 1
>>>
>>> Compilation exited abnormally with code 2 at Tue May 18 11:05:17
>>>
>>>
>>> Regards Christian Rudiger
>>>
>>>
>>> -- 
>>> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>>> Problem reports:       http://cygwin.com/problems.html
>>> Documentation:         http://cygwin.com/docs.html
>>> FAQ:                   http://cygwin.com/faq/
>>>
>>
>>
>>
> 
> 
> -- 
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Problem reports:       http://cygwin.com/problems.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/
> 
> 


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list