Loadlibrary problems with const object

2 views (last 30 days)
Jesse on 2 May 2011
Edited: Walter Roberson on 15 Jul 2016
I'm trying to load some .dll library functions for a camera driver into Matlab using the loadlibrary command without success. I'm using Win7 x64, running R2011a. Also, I have MS Visual Studio 2010 pro as the compiler. I've tried running this from both the matlabroot directory, as well as the directory containing the .dll and .h files (which has been added to the search path), and I'm running Matlab as administrator.
If I run this simple script:
dllfile = 'C:\Program Files\Andor SOLIS\Drivers\atmcd64d.dll';
hfile = 'C:\Program Files\Andor SOLIS\Drivers\ATMCD32D.H';
[nofound,warn] = loadlibrary(dllfile,hfile);
I get the following error stream:
??? Error using ==> loadlibrary at 441
Building atmcd64d_thunk_pcwin64 failed. Compiler output is:
cl -I"C:\Program Files\MATLAB\R2011a\extern\include" /Zp8 /W3
/nologo -I"C:\Program Files\Andor SOLIS\Drivers" -I"C:\Program Files\Andor
SOLIS\Drivers" "atmcd64d_thunk_pcwin64.c" -LD
atmcd64d_thunk_pcwin64.c(1284) : warning C4114: same type qualifier used
more than once
atmcd64d_thunk_pcwin64.c(1284) : error C2166: l-value specifies const object
Any ideas?
[nofound,warn] = loadlibrary(dllfile,hfile);

Answers (2)

Kaustubha Govind
Kaustubha Govind on 2 May 2011
If you are using 64-bit MATLAB, you must ensure that you are loading a 64-bit DLL. From the names of your files: atmcd64d.dll and ATMCD32D.H, it seems that the DLL is 64-bit, but the header file you are using to load it for the 32-bit version of the library. Could you verify if that is the case (the name doesn't necessarily tell us anything, so you can use the dumpbin utility with the /headers option to verify whether you have a 64-bit binary)? Are you able to load this DLL is a 64-bit C/C++ application outside of MATLAB?
Vijay on 1 Feb 2012
I'm also getting stuck on using the atmcd64d.dll from 64-bit Matlab via loadlibrary, with exactly the same compiler error (C2166: l-value specifies const object).
The supplier of this DLL (Andor) makes clear in their documentation that the atmcd32d.h header is meant to work with both the 32- and 64-bit versions of their DLL.
I'm curious to know if there's been any further progress by Jesse in trying to load atmcd64d.dll into 64-bit Matlab via loadlibrary?
Vijay Iyer
HHMI/Janelia Farm

Sign in to comment.

Vijay on 1 Feb 2012
Actually, I've just been able to successfully create the thunk file needed for 64-bit loadlibrary() operation.
The issue is with the OA_xxx functions in the amcd32d.h file. They use function signatures like: OA_Initialize(const char * const pcFilename,...)
The doubled-up use of const makes the compiler unhappy.
In general, the thunk-file generator for 64-bit loadlibrary is quite sensitive to syntax in header files that often worked under 32-bit loadlibrary(). In part it's because it requires strict C syntax. So generally, the header files have to be massaged to allow the thunk file generation to proceed. This was a new one for me.
In this case, those OA_xx functions are somewhat ancillary, so I just commented them out. If you need those functions, some signature change would be needed in the header to allow the loadlibrary() thunk file gen to work.
  1 Comment
Ofek on 15 Jul 2016
My own personal solution when confronting a very similar solution was to hijack and massage the generated thunk source. It seems that always (or nearly always?) just renaming the generated file to cpp and building it as such generates a valid thunk dll, which leaves one wondering why it was generated as a .c file in the first place.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!