Linking Mixed Mode and Managed Assemblies

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?aWduaGVucnk=?=

    Linking Mixed Mode and Managed Assemblies

    I have a managed C++ project and two C# projects. All are class library
    projects. The C++ project links with native C++ static libraries and
    references to one C# project. The projects structure goes something like this.

    Proj2_MCPP --(references)--Proj1_CSharp
    Proj3_CSharp --(references)--Proj2_MCPP and Proj1_CSharp

    My objective is to link the DLLs produced by the 3 projects into a single DLL.

    I tried the following scenario.
    1. csc Proj1_CSharp into a netmodule
    2. cl Proj2_MCPP with /LN and /clr:oldSyntax switch to produce .obj files
    3. csc Proj3_CSharp with /AddModule option and use .netmodule and .obj files
    as input
    4. Link 1, 2 and 3 into a dll.

    and I also tried this.
    1. csc Proj1_CSharp into a netmodule
    2. Build Proj2_MCPP from VS.NET 2005 (based on
    http://support.microsoft.com/kb/309805) to produce .netmodule and obj .files.
    3. csc Proj3_CSharp with /AddModule option and use .netmodule and .obj files
    as input
    4. Link 1, 2 and 3 into a dll.

    I never managed to reach step 4. I just stuck with error messages resulted
    from step 3.

    Am I doing the right thing? Or it is just not possible?

    Thanks - Henry
  • =?Utf-8?B?UGV0ZXIgUml0Y2hpZSBbQyMgTVZQXQ==?=

    #2
    RE: Linking Mixed Mode and Managed Assemblies

    Class library projects are DLLs. You can't directly link DLLs together into
    a new DLL.

    You could try a utility called ILMerge [1]; but I haven't tried it with
    mixed-mode DLLs.

    [1] http://research.microsoft.com/~mbarnett/ILMerge.aspx

    --
    Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.

    Microsoft MVP, Visual Developer - Visual C#


    "ignhenry" wrote:
    I have a managed C++ project and two C# projects. All are class library
    projects. The C++ project links with native C++ static libraries and
    references to one C# project. The projects structure goes something like this.
    >
    Proj2_MCPP --(references)--Proj1_CSharp
    Proj3_CSharp --(references)--Proj2_MCPP and Proj1_CSharp
    >
    My objective is to link the DLLs produced by the 3 projects into a single DLL.
    >
    I tried the following scenario.
    1. csc Proj1_CSharp into a netmodule
    2. cl Proj2_MCPP with /LN and /clr:oldSyntax switch to produce .obj files
    3. csc Proj3_CSharp with /AddModule option and use .netmodule and .obj files
    as input
    4. Link 1, 2 and 3 into a dll.
    >
    and I also tried this.
    1. csc Proj1_CSharp into a netmodule
    2. Build Proj2_MCPP from VS.NET 2005 (based on
    http://support.microsoft.com/kb/309805) to produce .netmodule and obj .files.
    3. csc Proj3_CSharp with /AddModule option and use .netmodule and .obj files
    as input
    4. Link 1, 2 and 3 into a dll.
    >
    I never managed to reach step 4. I just stuck with error messages resulted
    from step 3.
    >
    Am I doing the right thing? Or it is just not possible?
    >
    Thanks - Henry

    Comment

    • =?Utf-8?B?aWduaGVucnk=?=

      #3
      RE: Linking Mixed Mode and Managed Assemblies

      Thanks, Peter. I read somewhere that ILMerge, and Al.exe, only work for pure
      managed assemblies, but don't support mixed mode DLLs containing both managed
      and unmanaged code. I dropped them from my list.

      Right now I am looking at using CSharp compiler and VC++ linker. I've seen
      in internet newsgroups some people got it working successfully. My CSharp
      compiler is complaining that some classes are defined multiple times.
      Obviously, I am still missing something - probably simple.

      -- Henry

      "Peter Ritchie [C# MVP]" wrote:
      Class library projects are DLLs. You can't directly link DLLs together into
      a new DLL.
      >
      You could try a utility called ILMerge [1]; but I haven't tried it with
      mixed-mode DLLs.
      >
      [1] http://research.microsoft.com/~mbarnett/ILMerge.aspx
      >
      --
      Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.

      Microsoft MVP, Visual Developer - Visual C#
      >
      >
      "ignhenry" wrote:
      >
      I have a managed C++ project and two C# projects. All are class library
      projects. The C++ project links with native C++ static libraries and
      references to one C# project. The projects structure goes something like this.

      Proj2_MCPP --(references)--Proj1_CSharp
      Proj3_CSharp --(references)--Proj2_MCPP and Proj1_CSharp

      My objective is to link the DLLs produced by the 3 projects into a single DLL.

      I tried the following scenario.
      1. csc Proj1_CSharp into a netmodule
      2. cl Proj2_MCPP with /LN and /clr:oldSyntax switch to produce .obj files
      3. csc Proj3_CSharp with /AddModule option and use .netmodule and .obj files
      as input
      4. Link 1, 2 and 3 into a dll.

      and I also tried this.
      1. csc Proj1_CSharp into a netmodule
      2. Build Proj2_MCPP from VS.NET 2005 (based on
      http://support.microsoft.com/kb/309805) to produce .netmodule and obj .files.
      3. csc Proj3_CSharp with /AddModule option and use .netmodule and .obj files
      as input
      4. Link 1, 2 and 3 into a dll.

      I never managed to reach step 4. I just stuck with error messages resulted
      from step 3.

      Am I doing the right thing? Or it is just not possible?

      Thanks - Henry

      Comment

      • =?Utf-8?B?UGV0ZXIgUml0Y2hpZSBbQyMgTVZQXQ==?=

        #4
        RE: Linking Mixed Mode and Managed Assemblies

        Visual Studio doesn't support them, but compiling to netmodules could then be
        linked together as an assembly using Assembly Linker (al.exe).

        I'm not sure how to get c++ compiler to generate netmodules...

        --
        Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.

        Microsoft MVP, Visual Developer - Visual C#


        "ignhenry" wrote:
        Thanks, Peter. I read somewhere that ILMerge, and Al.exe, only work for pure
        managed assemblies, but don't support mixed mode DLLs containing both managed
        and unmanaged code. I dropped them from my list.
        >
        Right now I am looking at using CSharp compiler and VC++ linker. I've seen
        in internet newsgroups some people got it working successfully. My CSharp
        compiler is complaining that some classes are defined multiple times.
        Obviously, I am still missing something - probably simple.
        >
        -- Henry
        >
        "Peter Ritchie [C# MVP]" wrote:
        >
        Class library projects are DLLs. You can't directly link DLLs together into
        a new DLL.

        You could try a utility called ILMerge [1]; but I haven't tried it with
        mixed-mode DLLs.

        [1] http://research.microsoft.com/~mbarnett/ILMerge.aspx

        --
        Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.

        Microsoft MVP, Visual Developer - Visual C#


        "ignhenry" wrote:
        I have a managed C++ project and two C# projects. All are class library
        projects. The C++ project links with native C++ static libraries and
        references to one C# project. The projects structure goes something like this.
        >
        Proj2_MCPP --(references)--Proj1_CSharp
        Proj3_CSharp --(references)--Proj2_MCPP and Proj1_CSharp
        >
        My objective is to link the DLLs produced by the 3 projects into a single DLL.
        >
        I tried the following scenario.
        1. csc Proj1_CSharp into a netmodule
        2. cl Proj2_MCPP with /LN and /clr:oldSyntax switch to produce .obj files
        3. csc Proj3_CSharp with /AddModule option and use .netmodule and .obj files
        as input
        4. Link 1, 2 and 3 into a dll.
        >
        and I also tried this.
        1. csc Proj1_CSharp into a netmodule
        2. Build Proj2_MCPP from VS.NET 2005 (based on
        http://support.microsoft.com/kb/309805) to produce .netmodule and obj .files.
        3. csc Proj3_CSharp with /AddModule option and use .netmodule and .obj files
        as input
        4. Link 1, 2 and 3 into a dll.
        >
        I never managed to reach step 4. I just stuck with error messages resulted
        from step 3.
        >
        Am I doing the right thing? Or it is just not possible?
        >
        Thanks - Henry

        Comment

        • =?Utf-8?B?UGV0ZXIgUml0Y2hpZSBbQyMgTVZQXQ==?=

          #5
          RE: Linking Mixed Mode and Managed Assemblies

          Here's what I've been able to do:

          csc /target:module cstest.cs
          cl /clr:pure /FUSystem.dll /LN cpptest.cpp
          al /platform:x86 /t:lib /out:test.dll cpptest.netmodu le cstest.netmodul e

          This generates a dll (test.dll) that contains the two netmodules. When I
          added to another C# project as a reference I was able to add managed types
          from both netmodules.

          --
          Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.

          Microsoft MVP, Visual Developer - Visual C#


          "ignhenry" wrote:
          Thanks, Peter. I read somewhere that ILMerge, and Al.exe, only work for pure
          managed assemblies, but don't support mixed mode DLLs containing both managed
          and unmanaged code. I dropped them from my list.
          >
          Right now I am looking at using CSharp compiler and VC++ linker. I've seen
          in internet newsgroups some people got it working successfully. My CSharp
          compiler is complaining that some classes are defined multiple times.
          Obviously, I am still missing something - probably simple.
          >
          -- Henry
          >
          "Peter Ritchie [C# MVP]" wrote:
          >
          Class library projects are DLLs. You can't directly link DLLs together into
          a new DLL.

          You could try a utility called ILMerge [1]; but I haven't tried it with
          mixed-mode DLLs.

          [1] http://research.microsoft.com/~mbarnett/ILMerge.aspx

          --
          Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.

          Microsoft MVP, Visual Developer - Visual C#


          "ignhenry" wrote:
          I have a managed C++ project and two C# projects. All are class library
          projects. The C++ project links with native C++ static libraries and
          references to one C# project. The projects structure goes something like this.
          >
          Proj2_MCPP --(references)--Proj1_CSharp
          Proj3_CSharp --(references)--Proj2_MCPP and Proj1_CSharp
          >
          My objective is to link the DLLs produced by the 3 projects into a single DLL.
          >
          I tried the following scenario.
          1. csc Proj1_CSharp into a netmodule
          2. cl Proj2_MCPP with /LN and /clr:oldSyntax switch to produce .obj files
          3. csc Proj3_CSharp with /AddModule option and use .netmodule and .obj files
          as input
          4. Link 1, 2 and 3 into a dll.
          >
          and I also tried this.
          1. csc Proj1_CSharp into a netmodule
          2. Build Proj2_MCPP from VS.NET 2005 (based on
          http://support.microsoft.com/kb/309805) to produce .netmodule and obj .files.
          3. csc Proj3_CSharp with /AddModule option and use .netmodule and .obj files
          as input
          4. Link 1, 2 and 3 into a dll.
          >
          I never managed to reach step 4. I just stuck with error messages resulted
          from step 3.
          >
          Am I doing the right thing? Or it is just not possible?
          >
          Thanks - Henry

          Comment

          • Jeffrey Tan[MSFT]

            #6
            RE: Linking Mixed Mode and Managed Assemblies

            Hi Henry,

            I have added a reply to you in microsoft.publi c.dotnet.langua ges.vc
            newsgroup, please feel free to check it there, thanks.

            Best regards,
            Jeffrey Tan
            Microsoft Online Community Support
            =============== =============== ===========
            Delighting our customers is our #1 priority. We welcome your comments and
            suggestions about how we can improve the support we provide to you. Please
            feel free to let my manager know what you think of the level of service
            provided. You can send feedback directly to my manager at:
            msdnmg@microsof t.com.

            This posting is provided "AS IS" with no warranties, and confers no rights.

            Comment

            Working...