Skip to content

Commit d346e48

Browse files
committed
search for dll in separate function
1 parent 52c6400 commit d346e48

2 files changed

Lines changed: 65 additions & 38 deletions

File tree

lsl_get_dll.m

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
function lsl_fname = lsl_get_dll(binarypath, debugging)
2+
% Search for the lsl library
3+
% [lsl_fname] = lsl_get_dll(binarypath, debugging)
4+
%
5+
% In:
6+
% BinaryPath : Optionally the path to the locations of the liblsl bin folder (default: relative
7+
% to this .m file).
8+
%
9+
% DebugVersion : Optionally load the debug version of the library (default: false)
10+
%
11+
% Out:
12+
% lsl_fname : the filename of the library
13+
14+
if ~exist('binarypath','var') || isempty(binarypath)
15+
binarypath = [fileparts(mfilename('fullpath')) filesep 'bin'];
16+
end
17+
if ~exist('debugging','var') || isempty(debugging)
18+
debugging = false;
19+
end
20+
21+
if ispc
22+
ext = '.dll';
23+
elseif ismac
24+
ext = '.dylib';
25+
elseif isunix
26+
ext = '.so';
27+
else
28+
error('Your operating system is not supported by this version of the lab streaming layer API.');
29+
end
30+
31+
if strfind(computer,'64')
32+
bitness = '64';
33+
else
34+
bitness = '32';
35+
end
36+
37+
if debugging
38+
debug = '-debug';
39+
else
40+
debug = '';
41+
end
42+
43+
dll_fname = sprintf('liblsl%s%s%s', bitness, debug, ext);
44+
lsl_fname = fullfile(binarypath, dll_fname);
45+
46+
if ~exist(lsl_fname, 'file') && ~ispc
47+
new_dllpath = fullfile('/usr/lib/', dll_fname);
48+
if exist(new_dllpath, 'file')
49+
lsl_fname = new_dllpath;
50+
end %if
51+
end %if
52+
53+
if ~exist(lsl_fname,'file')
54+
error(['Apparently the file "' dllpath '" is missing on your computer. Cannot load the lab streaming layer.']);
55+
end
56+
57+
end
58+

lsl_loadlib.m

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,51 +24,20 @@
2424
% 2012-03-05
2525

2626
if ~exist('binarypath','var') || isempty(binarypath)
27-
binarypath = [fileparts(mfilename('fullpath')) filesep 'bin']; end
27+
binarypath = [];
28+
end
2829
if ~exist('debugging','var') || isempty(debugging)
29-
debugging = false; end
30+
debugging = false;
31+
end
3032
if ~exist('keep_persistent','var') || isempty(keep_persistent)
31-
keep_persistent = true; end
33+
keep_persistent = true;
34+
end
3235

3336
persistent lib;
3437
if keep_persistent && ~isempty(lib)
3538
hlib = lib;
3639
else
37-
if ispc
38-
ext = '.dll';
39-
elseif ismac
40-
ext = '.dylib';
41-
elseif isunix
42-
ext = '.so';
43-
else
44-
error('Your operating system is not supported by this version of the lab streaming layer API.');
45-
end
46-
47-
if strfind(computer,'64')
48-
bitness = '64';
49-
else
50-
bitness = '32';
51-
end
52-
53-
if debugging
54-
debug = '-debug';
55-
else
56-
debug = '';
57-
end
58-
59-
dll_fname = sprintf('liblsl%s%s%s', bitness, debug, ext);
60-
dllpath = fullfile(binarypath, dll_fname);
61-
62-
if ~exist(dllpath, 'file') && ~ispc
63-
new_dllpath = fullfile('/usr/lib/', dll_fname);
64-
if exist(new_dllpath, 'file')
65-
dllpath = new_dllpath;
66-
end %if
67-
end %if
68-
69-
if ~exist(dllpath,'file')
70-
error(['Apparently the file "' dllpath '" is missing on your computer. Cannot load the lab streaming layer.']);
71-
end
40+
dllpath = lsl_get_dll(binarypath, debugging);
7241

7342
% open the library and make sure that it gets auto-deleted when the handle is erased
7443
try

0 commit comments

Comments
 (0)