Click here to Skip to main content
15,064,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can only include a c++ dll if it doesn't have dependencies
[DllImport("example.dll", CallingConvention = CallingConvention.Cdecl)]
internal static extern void Exmaple(IntPtr value);

but if example.dll has dependencies like other libraries ( example2.dll )
it throw an exception System.DllNotFoundException

What I have tried:

I have tried adding tags in the project file
<ItemGroup Condition="'$(Configuration)'=='Debug'">
   <Content Include="/.../example.dylib">
<ItemGroup Condition="'$(Configuration)'=='Release'">
   <Content Include="/.../example.dylib">
Updated 9-Jan-21 13:40pm

Interesting - I assumed it just worked - long ago I 'wrapped' a commercial PGP library supplied as dlls, in a single 'shim' to offer 'aggregate functionality' to C#, made sure the required dll's were all 'with' the exe ie in the same path folder, and it just worked.

There is a discussion on the general case here c# - How can I specify a [DllImport] path at runtime? - Stack Overflow[^] and the reference from that Dynamic-Link Library Search Order - Win32 apps | Microsoft Docs[^] ... there are some useful things to try, for example, manually doing a LoadLibrary of the dependant dll before you call the 'top level' one, 'maybe' using SetDllDirectory

Unfortunately I can't easily test anything for you at the moment

[edit] I'd manually place all the dependant dll's in the output directory first and test like that .. when that's working, then work on the build 'copy' sequence .. btw, your project file has '/.../example.dylib' so I'd double check if it's working a) the '...' b) the dylib, or is that a folder name ? [/edit]

IMO when your EXE is a managed code one, the unmananged code DLLs will be located as always in the unmanaged world: either put them in your EXE's folder, or make sure their path is included in the Windows PATH environment variable.

Garth J Lancaster 9-Jan-21 20:41pm
yup - as per the official MS doc :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900