Bug 1055

Summary: problem with generated dll in MS C# environment
Product: binutils Reporter: Helmut Dipper <helmut.dipper>
Component: ldAssignee: unassigned
Status: RESOLVED INVALID    
Severity: normal CC: bug-binutils
Priority: P2    
Version: 2.15   
Target Milestone: ---   
Host: Target: i686-pc-cygwin
Build: i686-pc-cygwin-gnu Last reconfirmed:

Description Helmut Dipper 2005-07-07 13:31:58 UTC
My program written in MS C# (for example "nant" from sourceforge) uses a
function written in pure C and compiled and linked to a dll with cygwin-gcc: if
linked with option "-mno-cygwin" function is executed as expected. if linked
without the option "-mno-cygwin" program finishes execution after return from
function without any message. Linking a gcc-created *.o with MSVC-linker to a
dll is not possible, because the MSVC-linker cannot read the used dll's out of
the cygwin-environment.

versions:
cygwin: 1.5.16
gcc: version 3.3.3 (cygwin special)
ld: GNU ld version 2.15.94 20041229

gcc-commands:
gcc -v -g -shared -o test-cygwin.dll fct.c
gcc -v -g -shared -mno-cygwin -o test-mingw.dll fct.c

sources:
fct.c:
#if defined(WIN32) 
#   define DLL_EXPORT __declspec(dllexport)
#else
#   define DLL_EXPORT /**/
#endif

#include <stdio.h>
#include <string.h>

DLL_EXPORT void dll_fct (char *par)
{
   printf("executing dll_fct with parameter:%s\n",par);
}

test.cs:
using System;
using System.Runtime.InteropServices;   
class Class1
    {
         [DllImport("test-mingw.dll",
            EntryPoint="dll_fct",ExactSpelling=true,
            CharSet=CharSet.Ansi,
            CallingConvention=CallingConvention.StdCall
         )]
        private static extern void dll_fct(string par);

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args) {
            Console.WriteLine("before call dll_fct");
            dll_fct("hello");
            Console.WriteLine("after call dll_fct");
        }
    }
Comment 1 Dave Korn 2009-05-24 03:47:29 UTC
(In reply to comment #0)
> My program written in MS C# (for example "nant" from sourceforge) uses a
> function written in pure C and compiled and linked to a dll with cygwin-gcc: if
> linked with option "-mno-cygwin" function is executed as expected. if linked
> without the option "-mno-cygwin" program finishes execution after return from
> function without any message. 

  This much is expected.  It is not possible to use a Cygwin-native DLL without
the rest of the Cygwin runtime support present and correctly initialised, in
particular cygwin1.dll.

> Linking a gcc-created *.o with MSVC-linker to a
> dll is not possible, because the MSVC-linker cannot read the used dll's out of
> the cygwin-environment.

  This statement is unclear and confusing: is the MS linker trying to link a
cygwin DLL or a gcc-created .o?  Either way, it's impossible to tell from a
rough description whether this is just a manifestation of the same problem
above.  Compatibility with the MS tools has been much improved since this report
was filed, but if a problem can be demonstrated on up-to-date binutils we can
re-open this bug.

    cheers,
      DaveK