In a C project i'm building in Visual Studio (C++ 2010 Express), I use the MatLab engine to allow for a user to provide a custom function to use within the project. The problem is that this code also needs to be able to run on computers without MatLab installed on it, meaning that the required DLL's will not be available on the computer in that case. Of course this should only work when the user does not try to access the piece of code which calls the matlab engine (I have provided a flag for this).
I have 3 dll's that are needed for this scenario.
- libmx.dll
- libmex.dll
- libeng.dll
So far i have been able to load the libeng.dll at run-time using LoadLibrary and GetProcAddress. The other two DLL's are a bit harder though, apart from the C-code calling the MatLab engine, the code is also often compiled as a mex-file (MatLab executable), to allow users to call it from MatLab. When compiling as a mex-file, both libmx.dll and libmex.dll are dynamically linked by the mex compiler. This means that using LoadLibrary and GetProcAddress don't work for these DLL's.
Right now I just add the libmx and libmex LIB's to the linker properties in visual studio and this works fine, but will not be possible for someone who doesn't have MatLab installed.
I have tried using delayLoad and this works if I compile in Debug mode, but gives this build error when I compile in release mode.
1>C:\Program Files (x86)\MATLAB\R2012a\bin\win32\libmx.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2B8
Is there a way to just completely skip looking for / Loading these DLL's if the part of the code that uses them is not accessed?
This is the command line for the linker:
/OUT:"C:\Users\A.Vandenber\documents\visual studio 2010\Projects\Flash\Release\Flash.exe" /NOLOGO "C:\Program Files (x86)\MATLAB\R2012a\bin\win32\libmx.lib" "C:\Program Files (x86)\MATLAB\R2012a\bin\win32\libmex.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DELAYLOAD:"libmex.dll" /DELAYLOAD:"libmx.dll" /MANIFEST /ManifestFile:"Release\Flash.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\Users\A.Vandenber\documents\visual studio 2010\Projects\Flash\Release\Flash.pdb" /OPT:REF /OPT:ICF /PGD:"C:\Users\A.Vandenber\documents\visual studio 2010\Projects\Flash\Release\Flash.pgd" /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE
LoadLibrary()
andGetProcAddress()
) your feature DLL into the main program? – Preservative