【问题标题】:loadlibrary in 64-bit Matlab?64位Matlab中的加载库?
【发布时间】:2014-08-06 18:23:17
【问题描述】:

我正在尝试使用 loadlibrary() 将 C++ API(用于 SignalHound.com 上的 BB60C 收音机)加载到 Matlab 中,但它仅适用于 32 位 Matlab (R2014a)。 zip 文件here 包含 bb_api.h 头文件,并在其各自的文件夹中同时具有 32 位和 64 位 bb_api.dll。为了运行它,我将正确的 .dll 复制到带有 bb_api.h 的文件夹中并调用 loadlibrary('bb_api','bb_api.h')。虽然这适用于 32 位版本,但当我在 64 位 Matlab 中使用 64 位 .dll 时,出现以下错误:

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'`

API 中可用的所有方法等等。什么会导致此错误发生在 64 位而不是 32 位?

谢谢!

【问题讨论】:

  • 我联系了 Mathworks,显然要在 64 位 Matlab 中运行它,需要一个与 API 关联的 thunk 文件(其中没有 32 位 thunk 文件的概念),它充当兼容层。

标签: c++ matlab dll loadlibrary


【解决方案1】:

你说的是使用 C++,但是你的文件名为.c,这会触发使用 C 语言规则的编译。 Microsoft 编译器的 C 支持已经过时,这很可能是您的问题的根源。您可能想改用 C++。

除此之外,仔细查看发生错误的行,就像您在自己的代码中修复编译错误一样。

【讨论】:

    【解决方案2】:

    ***_thunk.c 文件由 matlab 附带的 perl 脚本自动生成,是许多类似错误的根源。

    这个事实(自动生成的 thunk 源在 c 中)是许多已记录看似奇怪的 loadlibrary limitations 和更多未记录的源。

    当遇到一个非常相似的问题时,我的解决方案是劫持这个自动生成的文件,将其重命名为 cpp 并构建我自己的 cpp 版本的 thunk。这需要一些黑客攻击,因为这个文件的生命周期只有几分之一秒。 Full details are here.

    【讨论】:

      猜你喜欢
      • 2016-02-13
      • 2011-11-09
      • 2012-10-18
      • 1970-01-01
      • 2011-01-16
      • 2011-07-23
      • 1970-01-01
      • 2016-10-29
      • 1970-01-01
      相关资源
      最近更新 更多