gcc links to libcmain when generating a dll

Arthur Schwarz home@slipbits.com
Thu May 22 18:37:41 GMT 2025


I can't figure this one out.

 > clear;g++ -flinker-output=dyn -o slip.dll *.o

generates:

/usr/lib/gcc/x86_64-pc-cygwin/12/../../../../x86_64-pc-cygwin/bin/ld: 
/usr/lib/gcc/x86_64-pc-cygwin/12/../../../../lib/libcygwin.a(libcmain.o): 
in function `main':
/usr/src/debug/cygwin-3.6.1-1/winsup/cygwin/lib/libcmain.c:37:(.text.startup+0x79): 
undefined reference to `WinMain'
collect2: error: ld returned 1 exit status

But I am developing a dll, not a windows application. The gcc.pdf manual 
says:

    -flinker-output=type
    This option controls code generation of the link-time optimizer. By
    default the
    linker output is automatically determined by the linker plugin. For
    debugging
    the compiler and if incremental linking with a non-LTO object file
    is desired,
    it may be useful to control the type manually.

    If type is ‘dyn’, code generation produces a shared library. In this
    case ‘-fpic’
    or ‘-fPIC’ is preserved, but not enabled automatically. This allows
    to build
    shared libraries without position-independent code on architectures
    where this
    is possible, i.e. on x86.

My code is not executable and nowhere links to or uses any Windows code. 
It does not have a WinMain method and there is no link to libcmain.o in 
the object folder (*.o does not have libcmain.o).

How do I get rid of this link error?


More information about the Cygwin mailing list