MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / preload_bundled_libraries

Function preload_bundled_libraries

src/src/main.cpp:66–90  ·  view source on GitHub ↗

@brief Preload critical XRT libraries from the executable directory @details This ensures that dlopen() calls within libraries find the bundled versions @note Only on Linux/Unix; Windows handles DLL loading differently

Source from the content-addressed store, hash-verified

64///@details This ensures that dlopen() calls within libraries find the bundled versions
65///@note Only on Linux/Unix; Windows handles DLL loading differently
66void preload_bundled_libraries() {
67 std::string exe_dir = utils::get_executable_directory();
68
69 // When running inside a snap, LD_LIBRARY_PATH already points at the
70 // bundled XRT libs (e.g. $SNAP/usr/lib/x86_64-linux-gnu). Passing a
71 // bare library name lets the dynamic linker resolve it via
72 // LD_LIBRARY_PATH, which avoids hard-coding the arch triplet.
73 // Outside of a snap the bundled libraries are expected to live in
74 // lib/ relative to the executable.
75 const char* snap_env = std::getenv("SNAP");
76 std::string lib_prefix = snap_env && *snap_env ? "" : exe_dir + "/lib/";
77
78 const std::vector<std::string> libraries = {
79 "libxrt_core.so.2", // Core - no dependencies
80 "libxrt_coreutil.so.2", // Depends on core
81 "libxrt_driver_xdna.so.2", // Driver
82 };
83
84 // Try to load the library with RTLD_GLOBAL so symbols are available to dependent libraries
85 // Don't care about failures
86 for (const auto& lib : libraries) {
87 std::string lib_path = lib_prefix + lib;
88 void* handle = dlopen(lib_path.c_str(), RTLD_LAZY | RTLD_GLOBAL);
89 }
90}
91#endif
92
93

Callers 1

mainFunction · 0.85

Calls 1

get_executable_directoryFunction · 0.85

Tested by

no test coverage detected