From a58ffa5b818ba05559afb8ade067598e52abae22 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sat, 1 Dec 2018 14:15:16 +0100 Subject: [PATCH] macos: rclaspell: get the dlopen to work --- src/aspell/rclaspell.cpp | 41 +++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/aspell/rclaspell.cpp b/src/aspell/rclaspell.cpp index 698832df..4fd8b6b8 100644 --- a/src/aspell/rclaspell.cpp +++ b/src/aspell/rclaspell.cpp @@ -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 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 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: