Skip to content

Commit 892f651

Browse files
committed
Fixup auto-get dylib for MacOS
1 parent a964337 commit 892f651

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

build_mex.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
else
1212
error('Neither liblsl64.lib nor lsl.lib found in bin/');
1313
end
14+
elseif ismac
15+
if exist(fullfile(binarypath, 'liblsl64.dylib'), 'file')
16+
libs = {'-llsl64'};
17+
elseif exist(fullfile(binarypath, 'liblsl.dylib'), 'file')
18+
libs = {'-llsl'};
19+
end
1420
elseif isunix
1521
libs = {'-llsl64','-ldl'};
1622
else

lsl_get_dll.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@
4545

4646
if ~exist(lsl_fname, 'file')
4747
if ispc
48-
% On Windows, also try simply 'lsl.dll'
4948
new_sopath = fullfile(binarypath, 'lsl.dll');
49+
elseif ismac && exist(fullfile(binarypath, 'liblsl.dylib'), 'file')
50+
new_sopath = fullfile(binarypath, 'liblsl.dylib');
5051
else
5152
new_sopath = fullfile('/usr/lib/', so_fname);
5253
end
@@ -83,9 +84,13 @@
8384
copyfile(fullfile(binarypath, 'liblsl_archive', 'lib', 'lsl.lib'),...
8485
fullfile(binarypath, 'lsl.lib'));
8586
elseif ismac
86-
untar(fullfile(binarypath, liblsl_url_fname),...
87-
fullfile(binarypath, 'liblsl_archive'));
88-
error('TODO: copyfile from liblsl_archive to lsl_fname on mac.');
87+
% Use system tar because Matlab untar does not preserve symlinks.
88+
mkdir(fullfile(binarypath, 'liblsl_archive'));
89+
system(['tar -C ' fullfile(binarypath, 'liblsl_archive') ' -xf ' fullfile(binarypath, liblsl_url_fname)]);
90+
copyfile(fullfile(binarypath, 'liblsl_archive', 'lib', '*.dylib'), binarypath);
91+
dylib_list = dir(fullfile(binarypath, '*.dylib'));
92+
[~, lib_ix] = min(cellfun(@length, {dylib_list.name}));
93+
lsl_fname = fullfile(dylib_list(lib_ix).folder, dylib_list(lib_ix).name);
8994
elseif isunix
9095
error(['Automatic extraction of debian package not yet supported.', ...
9196
' Please install manually: ' fullfile(binarypath, liblsl_url_fname)]);

lsl_loadlib.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@
4343
try
4444
hlib = lsl_loadlib_(dllpath);
4545
catch e
46-
disp('This error is probably because lsl_loadlib_ mex file is not on the path.');
47-
disp('Try running build_mex.m. If that was successful, make sure the liblsl-Matlab/bin folder is added to the path.');
4846
disp('See https://github.com/labstreaminglayer/liblsl-Matlab/#troubleshooting for further troubleshooting tips');
49-
error(['Error loading the liblsl library: ', e.message]);
47+
error(['Error loading the liblsl library: ', e.message,...
48+
' Make sure liblsl-Matlab/bin is added to path and try running build_mex.m']);
5049
end
5150

5251
hlib.on_cleanup = onCleanup(@()lsl_freelib_(hlib));

0 commit comments

Comments
 (0)