跪求高手,Matlab调用Lingo出错问题
在最新的Lingo 15.0版本里已经有了Matlab调用Lingo的例子,但运行有错误。clear; clc;
% By default, 64-bit Lingo API is in the C:\LINGO64_15 folder
addpath('C:\\LINGO64_15');
% Load the Lingo API
loadlibrary('Lingd64_15', 'Lingd15.h');
if ~libisloaded('Lingd64_15')
error('Cannot load LINGO library');
end
% Print out LINGO library functions
libfunctions('Lingd64_15', '-full');
% Create the Lingo environment
pLingo = calllib('Lingd64_15', 'LScreateEnvLng');
if ~( exist('pLingo', 'var') && isa(pLingo, 'lib.pointer') )
error('Cannot create LINGO environment object');
end
% Open a Lingo log file
nError = calllib('Lingd64_15', 'LSopenLogFileLng', pLingo, 'C:\\LINGO64_15\\testLingoLib15.log');
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG'), error('Cannot open LINGO log file'); end
% Staffing needs
dNeeds = ;
% Pointers to memory transfer areas
dNeedsPtr = libpointer('doublePtr', dNeeds);
dStartPtr = libpointer('doublePtr', zeros(1, 7));
dOnDutyPtr = libpointer('doublePtr', zeros(1, 7));
dStatusPtr = libpointer('doublePtr', -1);
dTotalPtr = libpointer('doublePtr', 0);
nPointerNowPtr = libpointer('int32Ptr', 0);
% Pass memory transfer pointers to LINGO
nError = calllib('Lingd64_15', 'LSsetPointerLng', pLingo, dNeedsPtr, nPointerNowPtr);
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG'), error('Cannot assign pointer'); end
nError = calllib('Lingd64_15', 'LSsetPointerLng', pLingo, dStartPtr, nPointerNowPtr);
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG'), error('Cannot assign pointer'); end
nError = calllib('Lingd64_15', 'LSsetPointerLng', pLingo, dOnDutyPtr, nPointerNowPtr);
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG'), error('Cannot assign pointer'); end
nError = calllib('Lingd64_15', 'LSsetPointerLng', pLingo, dTotalPtr, nPointerNowPtr);
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG'), error('Cannot assign pointer'); end
nError = calllib('Lingd64_15', 'LSsetPointerLng', pLingo, dStatusPtr, nPointerNowPtr);
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG'), error('Cannot assign pointer'); end
% Set up the command script
csScript = 'SET ECHOIN 1 \n';
csScript = ;
csScript = ;
csScript = ;
% Run the script
nError = calllib('Lingd64_15', 'LSexecuteScriptLng', pLingo, sprintf(csScript));
if ~strcmp( nError, 'LSERR_NO_ERROR_LNG'), error('Cannot execute script'); end
% Close log file
calllib('Lingd64_15', 'LScloseLogFileLng', pLingo);
% Optimal?
if get(dStatusPtr, 'value')
error('Unable to solve!');
else
% Display solution
disp(['Start : ' num2str(dStartPtr.value)]);
disp(['Needs : ' num2str(dNeedsPtr.value)]);
disp(['On Duty: ' num2str(dOnDutyPtr.value)]);
end
% Free Lingo environment
calllib('Lingd64_15', 'LSdeleteEnvLng', pLingo);
但调用出现如下错误:
??? Error using ==> loadlibrary>lFullPath at 545
Could not find file Lingd15.h.
Error in ==> loadlibrary at 220
header=lFullPath(header);
Error in ==> Staff at 7
loadlibrary('Lingd64_15', 'Lingd15.h');
注意两个问题:
1. LINGO安装路径;
2. MATLAB与LINGO的版本匹配,32位,64位要对应;
安装路径是默认的C盘,都是64位的
没有MATLAB,不方便验证,错误说明是找不到“Lingd64_15.h"这个文件,你看下这个文件位置在哪,然后把路径修正下应该就可以了。
一种简单粗暴的方法应该就是把这个文件扔到”C:\LINGO64_15"目录下。
这个文件就是Lingo15自带的例子
页:
[1]