macos: rclaspell: get the dlopen to work

This commit is contained in:
Jean-Francois Dockes 2018-12-01 14:15:16 +01:00
parent 9a9e10c7d6
commit a58ffa5b81

View File

@ -71,12 +71,16 @@ static std::mutex o_aapi_mutex;
badnames += #NM + string(" "); \
}
static const char *aspell_lib_suffixes[] = {
".so",
".so.15",
".so.16"
static const vector<string> aspell_lib_suffixes {
#if defined(__APPLE__)
".15.dylib",
".dylib",
#else
".so",
".so.15",
".so.16",
#endif
};
static const unsigned int nlibsuffs = sizeof(aspell_lib_suffixes) / sizeof(char *);
// Stuff that we don't wish to see in the .h (possible sysdeps, etc.)
class AspellData {
@ -160,16 +164,39 @@ bool Aspell::init(string &reason)
return false;
}
// Don't know what with Apple and (DY)LD_LIBRARY_PATH. Does not work
// So we look in all ../lib in the PATH...
#if defined(__APPLE__)
vector<string> path;
const char *pp = getenv("PATH");
if (pp) {
stringToTokens(pp, path, ":");
}
#endif
reason = "Could not open shared library ";
string libbase("libaspell");
string lib;
for (unsigned int i = 0; i < nlibsuffs; i++) {
lib = libbase + aspell_lib_suffixes[i];
for (const auto& suff : aspell_lib_suffixes) {
lib = libbase + suff;
reason += string("[") + lib + "] ";
if ((m_data->m_handle = dlopen(lib.c_str(), RTLD_LAZY)) != 0) {
reason.erase();
goto found;
}
#if defined(__APPLE__)
// Above was the normal lookup: let dlopen search the directories.
// Here is for Apple. Also look at all ../lib along the PATH
for (const auto& dir : path) {
string lib1 = path_canon(dir + "/../lib/" + lib);
if ((m_data->m_handle = dlopen(lib1.c_str(), RTLD_LAZY)) != 0) {
reason.erase();
lib=lib1;
goto found;
}
}
#endif
}
found: