Archived Forum Post

Index of archived forum posts

Question:

Mixed-mode .NET Assembly with static linkage?

Oct 10 '17 at 11:37

From your site, i can download .Net Dll and it works fine.

But in my case, i would like to have static version for .Net 4.5 library. Could you please provide me this one. I would like to import the lib directly into my App. I tried ILMerge for dll but no luck since the DLL was written in native C/C++.


Answer

Unfortunately, it is not possible (but an alternative is to try using the Chilkat Mono build).

When linking (to produce the Chilkat .NET assembly) with the static runtime lib is attempted, this error occurs:

cl : Command line error D8016: '/clr' and '/MT' command-line options are incompatible

After Googling the subject, I find answers such as this:

Mixed-mode compilation won't allow static CRT linkage. Use /MD (which uses the DLL version of the CRT).
See https://msdn.microsoft.com/en-us/library/ffkc918h.aspx

You may instead try using the Chilkat Mono package. It can be used from Visual Studio just like any other assembly. The Chilkat Mono package is different in that it is comprised of 2 DLLs (not 1). The 1st is a 100% managed assembly that you build following the instructions at https://www.chilkatsoft.com/mono.asp (This is to build the chilkatMono.dll from the .cs sources provided.) The 100% managed assembly utilizes the unmanaged implementation via Interop. Therefore, it calls into ChilkatMono-9_5_0.dll via P/Invoke (see http://www.mono-project.com/docs/advanced/pinvoke/ ) The ChilkatMono-9_5_0.dll is a statically linked DLL. The difficulty you may encounter is making sure the .NET runtime can find the unmanaged DLL. For this, it helps to be aware of the existence of ChilkatConst.cs, which has this define:

public const string DllPath = "chilkatMono-9_5_0";

This DllPath is used in the DllImports of the .cs sources.


Answer

For people who failed with mono version, use this embedder from github: https://github.com/boxedapp/bxilmerge/