function ret = findLinkObject(buildInfo, libname)
% findLinkObject searches for a link object with matching Name in the
% LinkObj vector of buildInfo

% Copyright 2004-2020 The MathWorks, Inc.

ret = [];

names = get(buildInfo.LinkObj,'Name');

% if there are no link objects, then just return
if isempty(names)
    return;
end

% if there is only one LinkObj, then the names returned will be a char
% array.  this needs to be turned into a cell array;
if ~iscell(names)
    names = {names};
end

% Strip file extensions before checking for a match
libname = regexprep(libname, '\..*$', '', 'once');
names = regexprep(names, '\..*$', '', 'once');

[found, idx] = ismember(libname,names);
if (found)
    ret = buildInfo.LinkObj(idx);
end
