473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
Jun 27 '08 #1
5 2776
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.
http://www.peterRitchie.com/blog/
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
Jun 27 '08 #2
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.
http://www.peterRitchie.com/blog/
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
Jun 27 '08 #3
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.
http://www.peterRitchie.com/blog/
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.
http://www.peterRitchie.com/blog/
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
Jun 27 '08 #4
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.netmodule cstest.netmodule

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.
http://www.peterRitchie.com/blog/
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.
http://www.peterRitchie.com/blog/
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
Jun 27 '08 #5
Hi Henry,

I have added a reply to you in microsoft.public.dotnet.languages.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:
ms****@microsoft.com.

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

Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Edward Diener | last post by:
I received no answers about this the first time I posted, so I will try again. My inability to decipher an MSDN topic may find others who have the same inability and someone who can decipher and...
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
8
by: Nadav | last post by:
Hi, I am writing a performence critical application, this require me to stick to unmanaged C++ as performance is much better using unmanaged C++ ( about 33% better ), Still, I am trying to avoid...
0
by: Drew | last post by:
I am attempting to clean up some code by breaking a large mixed-mode Managed C++ library into two. I cannot get the darn thing to compile or link (depending on what I do). I have two...
7
by: Lee Crabtree | last post by:
I'm starting work on what will eventually be a very, very LARGE project. A lot of the project involves taking C/C++ class libraries and wrapping them with managed C++. I'd like to minimize the...
2
by: Ubergeek | last post by:
I recently came accross an article that stated that there were unresolved issued with calling native (i.e. "unmanaged" C++) from managed C++. Does anyone know what the precise details of this...
8
by: Edward Diener | last post by:
By reuse, I mean a function in an assembly which is called in another assembly. By a mixed-mode function I mean a function whose signature has one or more CLR types and one or more non-CLR...
0
by: emu | last post by:
Hi All, I have an unmanaged C++ application that references a mixed mode image DLL (mixed managed and unmanaged). Under .NET 1.1 we could trust the dll (the mixed mode dll) by running the...
11
by: =?Utf-8?B?aWduaGVucnk=?= | last post by:
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.