开发者

Can I use both C# and C++/CLI in a single assembly?

开发者 https://www.devze.com 2022-12-31 10:53 出处:网络
Can I put together both C# and C++/CLI source files in a single project, and then comp开发者_StackOverflow社区ile them to obtain a single .DLL assembly?You can obtain single DLL from code both in c++/

Can I put together both C# and C++/CLI source files in a single project, and then comp开发者_StackOverflow社区ile them to obtain a single .DLL assembly?


You can obtain single DLL from code both in c++/cli and c# using command line tools. Let's assume you have two files: A.cc with C++/CLI code and B.cs with C# code. It should look something like this:

  • First compile c++ code into .obj file cl.exe /MD /c /clr A.cc
  • Compile c# code into "module" adding previously created .obj with /addmodule switch: csc.exe /target:module /addmodule:A.obj B.cs
  • Then link the module into single DLL: link.exe /DLL /LTCG /NOENTRY /CLRIMAGETYPE:IJW A.obj B.netmodule

I haven't tested it but it should work.

0

精彩评论

暂无评论...
验证码 换一张
取 消