0

I am trying to load a C++ API (for the BB60C radio at SignalHound.com) into Matlab using loadlibrary() but it is only working in 32-bit Matlab (R2014a). The zip file here contains the bb_api.h header file and has both a 32-bit and 64-bit bb_api.dll in their respective folder. To run it, I copy the correct .dll into the folder with bb_api.h and call loadlibrary('bb_api','bb_api.h'). While this works for the 32-bit version, when I use the 64-bit .dll in 64-bit Matlab, I get the following error:

Error using loadlibrary (line 422)
Building bb_api_thunk_pcwin64 failed.  Compiler output is:
cl -I"C:\Program Files\MATLAB\R2014a\extern\include"  /W3  /nologo  /D_CRT_SECURE_NO_DEPRECATE
/D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0   -I"C:\Program Files\MATLAB\R2014a\extern\include" -I"C:\Program
Files\MATLAB\R2014a\simulink\include" -I"C:\Users\mimhof\Documents\GitHub\SDR\Matlab"
-I"C:\Users\mimhof\Documents\GitHub\SDR\Matlab" "bb_api_thunk_pcwin64.c" -LD -Fe"bb_api_thunk_pcwin64.dll"
bb_api_thunk_pcwin64.c
C:\Users\mimhof\Documents\GitHub\SDR\Matlab\bb_api.h(202) : error C2061: syntax error : identifier 'bbOpenDevice'
C:\Users\mimhof\Documents\GitHub\SDR\Matlab\bb_api.h(202) : error C2059: syntax error : ';'
C:\Users\mimhof\Documents\GitHub\SDR\Matlab\bb_api.h(202) : error C2059: syntax error : 'type'
C:\Users\mimhof\Documents\GitHub\SDR\Matlab\bb_api.h(203) : error C2061: syntax error : identifier 'bbCloseDevice'
C:\Users\mimhof\Documents\GitHub\SDR\Matlab\bb_api.h(203) : error C2059: syntax error : ';'
C:\Users\mimhof\Documents\GitHub\SDR\Matlab\bb_api.h(203) : error C2059: syntax error : 'type'`

and so on for all the methods available in the API. What would cause this error to occur in 64-bit and not 32-bit?

Thanks!

MikeImhof
  • 1
  • 2
  • I contacted Mathworks and apparently to run it in 64-bit Matlab there needs to be a thunk file associated with the API (where there is no concept of a thunk file in 32-bit) that acts as a compatibility layer. – MikeImhof Aug 06 '14 at 21:05

2 Answers2

0

You talk about using C++, but your file is named .c, which triggers compilation using the C language rules. The Microsoft compiler's C support is pretty outdated, and it's likely that is the source of your problems. You may want to use C++ instead.

Beyond that, take a close look at the line where the error occurs, just as if you were fixing compile errors in your own code.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
0

The ***_thunk.c file is auto-generated by a perl script shipped with matlab, and is the source of many similar errors.

This fact (the auto generated thunk source is in c) is the source of many documented seemingly weird loadlibrary limitations and many more undocumented ones.

My solution when being hit by a very similar issue was to hijack this auto-generated file, rename it to cpp and build my own cpp version of the thunk. This required some hacking, as this file lifespan is a fraction of a second. Full details are here.

Ofek Shilon
  • 14,734
  • 5
  • 67
  • 101