Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DllImport can't find dll even though dll is in same folder as executable

I'm trying to use the llvm-fs project, which provides llvm bindings for F#. I have compiled the LLVM-3.1.dll file with --enable-shared and it now resides in same directory as my compiled executable (I checked with Environment.CurrentDirectory). The DllImport in llvm-fs looks like:

[<DllImport(
    "LLVM-3.1.dll",
    EntryPoint="LLVMModuleCreateWithName",
    CallingConvention=CallingConvention.Cdecl,
    CharSet=CharSet.Ansi)>]
extern void* (* LLVMModuleRef *) moduleCreateWithNameNative(string ModuleID)

Yet when I run my application it errors with:

Unable to load DLL 'LLVM-3.1.dll': The specified module could not be found.
(Exception from HRESULT: 0x8007007E)

How do I get the DLL to be loaded? For reference, here's the exact DLL I'm trying to load.

like image 658
Callum Rogers Avatar asked Aug 30 '12 07:08

Callum Rogers


2 Answers

This:

"The specified module could not be found"

can point to some library, which LLVM-3.1.dll depends from, not the LLVM-3.1.dll itself.

like image 169
Dennis Avatar answered Oct 22 '22 13:10

Dennis


When DLL or EXE fail to load as in this case Depends.exe is very handy - it display the complete EXE/DLL dependency tree, highlighting what cannot be loaded or it is missing.

like image 41
MiMo Avatar answered Oct 22 '22 12:10

MiMo