【问题标题】:Unable to load a library in MATLAB无法在 MATLAB 中加载库
【发布时间】:2013-01-23 00:53:40
【问题描述】:

我用 Visual C++ 2008 SP1 编写了一个非常简单的程序。 它只是将两个数字相加。 DLLTest.cpp 是:

#include "DllTest.h"

    __declspec(dllexport) double Add(double a, double b)
    {
    return( a + b );
}

而 DllTest.h 是:

#ifndef _DLL_TEST_H_
#define _DLL_TEST_H_
#endif

__declspec(dllexport) double Add( double, double);

我使用 Visual C++ 2008 构建 DLL。当我尝试使用 loadlibrary 加载库时,出现以下错误:

???在 422 Building DllTest_thunk_pcwin64 处使用 ==> loadlibrary 时出错。编译器输出为: DllTest_thunk_pcwin64.c C:\Users\Admin\Desktop\DllTest.h(5):错误 C2054: 预期 '(' 跟随 'EXPORTED_FUNCTION' C:\Users\Admin\Desktop\DllTest.h(5):错误 C2085:“添加”:不在 形式参数列表 DllTest_thunk_pcwin64.c(40) : 错误 C2085: 'int8' :不在形式参数列表 DllTest_thunk_pcwin64.c(41) 中: 错误 C2085:“uint8”:不在形式参数列表中 DllTest_thunk_pcwin64.c(42):错误 C2085:'int16':不是正式的 参数列表 DllTest_thunk_pcwin64.c(43):错误 C2085:'uint16': 不在形式参数列表 DllTest_thunk_pcwin64.c(44) 中:错误 C2085:'int32':不在形式参数列表中 DllTest_thunk_pcwin64.c(45):错误 C2085:'uint32':不是正式的 参数列表 DllTest_thunk_pcwin64.c(46):错误 C2085:'int64': 不在形式参数列表 DllTest_thunk_pcwin64.c(47) 中:错误 C2085: 'uint64' : 不在形式参数列表中 DllTest_thunk_pcwin64.c(48):错误 C2085:'voidPtr':不是正式的 参数列表 DllTest_thunk_pcwin64.c(49):错误 C2085:“字符串”: 不在形式参数列表 DllTest_thunk_pcwin64.c(51) 中:错误 C2082:重新定义形式参数“EXPORTED_FUNCTION” DllTest_thunk_pcwin64.c(51):错误 C2143:语法错误:缺少“;” 在 'type' DllTest_thunk_pcwin64.c(52) 之前:错误 C2085: 'EXPORTED_FUNCTIONdoubledoubledoubleThunk' : 不在形式参数中 列出 DllTest_thunk_pcwin64.c(52):错误 C2143:语法错误:缺失 ';'在'{'之前

我只想在 MATLAB 中加载一个用 Visual C++ 编写的简单程序。我该如何解决这个问题?

【问题讨论】:

  • 您使用的是什么操作系统(32/64 位)和 Matlab 版本?

标签: matlab visual-c++ dll


【解决方案1】:

感谢您考虑我的问题。 我发现了问题。其实有两个问题: 1) MATLAB 是 64 位的,但我制作了 32 位 DLL,我不得不更改 Visual Studio 中的设置以制作 64 位 DLL。 2) MATLAB 用于加载 DLL 的编译器似乎与 'extern "C"' 命令有问题。所以,我改变了这样的标题:

#ifndef DllTest_h
#define DllTest_h

#include <stdio.h>

#ifdef __cplusplus

extern "C" {

#endif
__declspec(dllexport) double Add( double, double);

#ifdef __cplusplus
}
#endif


#endif

终于成功了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多