undefined reference to `_msgDebug' in GCC

Phil Betts Phil.Betts@ascribe.com
Tue Feb 5 16:45:00 GMT 2008

Anik Pal wrote on Tuesday, February 05, 2008 3:12 PM::

> Phil,
> Thanks for the info you provided. I'm not conversant with GCC.
> I remove the path for regular library like libm.a, and all the paths
> specified in posix , now my linker option is as follows
> -L/cygdrive/f/geolog6.6.1/lib -lcgg -llicence -llogs_dll -lPGILc_dll
> -lPGILcTool_dll -lcgs  -lgeolog6 -L/cygdrive/D/cygwin/lib/mingw
> -lmsvcrt 
> -Bstatic -lm

You've only done half of what I said.

You only need this:

-L/cygdrive/f/geolog6.6.1/lib -lcgg -llicence -llogs_dll \
-lPGILc_dll -lPGILcTool_dll -lcgs  -lgeolog6

Here's why:

-L/cygdrive/D/cygwin/lib/mingw = look in the mingw lib directory
when linking.  You don't want to do that if you're compiling a
cygwin program, because the mingw libraries expect the program 
to be linked with msvcrt (see below)

-lmsvcrt = link to the Microsoft Visual C Runtime library. You 
definitely don't want this if you're compiling a cygwin program.

-Bstatic -lm = link with the static math library.  As I 
previously explained, the math library is integral to the cygwin 
C runtime library, so you just don't need this.

You should never specify a C runtime library to the compiler 
because  the compiler is generating code for a specific runtime 
library and if you force the linker to link with a different one 
you are likely to get all sorts of linkage errors.

If the above options don't work, then it's likely that your code
(or one of the libraries in geolog6.6.1/lib has calls to native
Windows functions.  If this is the case, you have two options:

1) replace all Windows function calls with their POSIX equivalent.
This will make your code portable to many more platforms.

2) If this is not possible, compile a native Windows program. For 
this you can either use the mingw version of gcc (where you'll 
need to use DOS style paths), or you can use cygwin's gcc in 
cross-compilation mode by specifying the -mno-cygwin option to gcc.
Note that if you do this, you won't be able to link to any of the 
cygwin libraries.  You don't need to change the link options from
those given above - gcc will automatically link with the msvcrt.dll

If you do decide to compile a native windows application, any 
further questions would be off-topic for this list - the clue is in
the "no-cygwin" bit ;-)

> But I'm not sure how to remove the dependency on libmsvcrt.a (that
> comes with mingw lib in cygwin).

If you've followed the above, you should now be able to answer that

> What is the equivalent lib in cygwin/lib? 

cygwin1.dll is cygwin's libc.  Just leave it up to the compiler 
to figure out which C library it needs to link to.
> Moreover I followed the solution stated in the following
> url to get rid of linking "undefined reference symbol __chkstk"
> http://eegeerg.blogspot.com/2008_01_01_archive.html#4158852069709002699
> which actually states to copy chkstk.OBJ from MSVC/lib and rename to
> chkstk.o and link with this.
> Now linking error goes but when try to execute this exe, it doesn't
> gives any error message but terminate unexpectedly.

That link says this:
| This is the error you get when you try to link a msvc6 compiled 
| library with gcc on mingw

If you try to mix MSVC code with cygwin code, you are asking for
trouble.  As I said in my original reply, decide whether you want
a cygwin program or a native Windows program and stick to your 


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