auriamg / macdylibbundler

Utility to ease bundling libraries into executables for OSX
MIT License
550 stars 83 forks source link

plugins gets copied to libs directory #14

Closed vygr closed 3 years ago

vygr commented 9 years ago

The reason this is happening is that using 'otool -L' on a dylib includes the ID in the output !!!

So you need to find out if there is an ID and remove it from the output line list !

Here is a quick fix I did, that you may like to use, or your own variation on this. Note I use 'auto', so put -std=c++11 on your makefile lines !

Best regards

Chris

void collectDependencies(std::string filename, std::vectorstd::string& lines) { // execute "otool" on the given file and collect the command's output std::string cmd = "otool -D " + filename; std::string id_output = system_get_output(cmd); auto start = std::find(id_output.begin(), id_output.end(), '\n') + 1; auto end = std::find(start, id_output.end(), '\n');

cmd = "otool -L " + filename;
std::string output = system_get_output(cmd);

if(output.find("can't open file")!=std::string::npos or output.find("No such file")!=std::string::npos or output.size()<1)
{
    std::cerr << "Cannot find file " << filename << " to read its dependencies" << std::endl;
    exit(1);
}

//remove id we don't want !!!
if (start != end)
{
  start = std::find(output.begin(), output.end(), '\n') + 1;
  end = std::find(start, output.end(), '\n') + 1;
  output = std::string(output.begin(), start) + std::string(end, output.end());
}

// split output
tokenize(output, "\n", &lines);

}

auriamg commented 9 years ago

Hi, the preferred way to submit fixes on github is pull requets, do you think you could submit that as a pull request? Makes it much easier to review

vygr commented 9 years ago

Never done one before so I just thought I'd let you know what the problem was :)

You had a FIXME comment that showed you didn't yet know what the issue was so if you'd like to fix it now you know, go ahead.

The gist of my fix was just to check if there was an ID present in the file using otool -D, and if so just chop the second line out of the output from the subsequent otool -L output. Not exactly the most elegant solution, there may be a far better way !

Best regards

Chris

SCG82 commented 3 years ago

Fixed in 63b13da