|
| 1 | +diff --git a/apps/mola-cli.cpp b/apps/mola-cli.cpp |
| 2 | +index 2bd97ff..d77ceda 100644 |
| 3 | +--- a/apps/mola-cli.cpp |
| 4 | ++++ b/apps/mola-cli.cpp |
| 5 | +@@ -23,7 +23,11 @@ |
| 6 | + #include <mrpt/core/exceptions.h> |
| 7 | + #include <mrpt/rtti/CObject.h> |
| 8 | + #include <mrpt/system/filesystem.h> |
| 9 | ++#if defined(_WIN32) |
| 10 | ++#include <io.h> // _write() |
| 11 | ++#else |
| 12 | + #include <unistd.h> // write() |
| 13 | ++#endif |
| 14 | + |
| 15 | + #include <CLI/CLI.hpp> |
| 16 | + #include <atomic> |
| 17 | +@@ -48,7 +52,11 @@ void mola_signal_handler([[maybe_unused]] int s) |
| 18 | + // raw write() to stderr. The actual shutdown (which logs, sleeps and joins |
| 19 | + // threads) is done by the main thread as soon as spin() returns. |
| 20 | + static const char msg[] = "\nTermination signal caught. Shutting down...\n"; |
| 21 | ++#if defined(_WIN32) |
| 22 | ++ [[maybe_unused]] const auto n = ::_write(2, msg, sizeof(msg) - 1); |
| 23 | ++#else |
| 24 | + [[maybe_unused]] const auto n = ::write(STDERR_FILENO, msg, sizeof(msg) - 1); |
| 25 | ++#endif |
| 26 | + |
| 27 | + if (auto* app = theApp.load()) |
| 28 | + { |
| 29 | +@@ -58,6 +66,11 @@ void mola_signal_handler([[maybe_unused]] int s) |
| 30 | + |
| 31 | + void mola_install_signal_handler() |
| 32 | + { |
| 33 | ++#if defined(_WIN32) |
| 34 | ++ // No sigaction() on Windows: |
| 35 | ++ std::signal(SIGINT, &mola_signal_handler); |
| 36 | ++ std::signal(SIGTERM, &mola_signal_handler); |
| 37 | ++#else |
| 38 | + struct sigaction sigIntHandler; |
| 39 | + |
| 40 | + sigIntHandler.sa_handler = &mola_signal_handler; |
| 41 | +@@ -71,6 +84,7 @@ void mola_install_signal_handler() |
| 42 | + // the main MOLA loop keeps running, so the process never exits and lingers |
| 43 | + // with its ROS 2 endpoints still advertised but no longer served. |
| 44 | + sigaction(SIGTERM, &sigIntHandler, nullptr); |
| 45 | ++#endif |
| 46 | + } |
| 47 | + |
| 48 | + // Default task for mola-cli: launching a SLAM system |
| 49 | +diff --git a/src/MolaDLL_Loader.cpp b/src/MolaDLL_Loader.cpp |
| 50 | +index ec376eb..6dcee68 100644 |
| 51 | +--- a/src/MolaDLL_Loader.cpp |
| 52 | ++++ b/src/MolaDLL_Loader.cpp |
| 53 | +@@ -26,6 +26,11 @@ |
| 54 | + |
| 55 | + #if defined(__unix__) || defined(__APPLE__) |
| 56 | + #include <dlfcn.h> |
| 57 | ++#elif defined(_WIN32) |
| 58 | ++#ifndef NOMINMAX |
| 59 | ++#define NOMINMAX |
| 60 | ++#endif |
| 61 | ++#include <windows.h> // LoadLibraryA(), FreeLibrary() |
| 62 | + #endif |
| 63 | + |
| 64 | + /** From internal_load_lib_modules() */ |
| 65 | +@@ -81,11 +86,17 @@ void internal_load_lib_modules( |
| 66 | + |
| 67 | + void* handle = dlopen(lib.wholePath.c_str(), RTLD_LAZY); |
| 68 | + #else |
| 69 | +- HMODULE handle = LoadLibrary(lib.wholePath.c_str()); |
| 70 | ++ void* handle = LoadLibraryA(lib.wholePath.c_str()); |
| 71 | + #endif |
| 72 | + if (handle == nullptr) |
| 73 | + { |
| 74 | ++#if defined(_WIN32) |
| 75 | ++ const std::string err_str = |
| 76 | ++ mrpt::format("LoadLibrary() error code %lu", static_cast<unsigned long>(GetLastError())); |
| 77 | ++ const char* err = err_str.c_str(); |
| 78 | ++#else |
| 79 | + const char* err = dlerror(); |
| 80 | ++#endif |
| 81 | + if (!err) err = "(error calling dlerror())"; |
| 82 | + THROW_EXCEPTION(mrpt::format( |
| 83 | + "Error loading module: `%s`\ndlerror(): `%s`", lib.wholePath.c_str(), err)); |
| 84 | +@@ -117,7 +128,7 @@ void internal_unload_lib_modules() |
| 85 | + #if defined(__unix__) || defined(__APPLE__) |
| 86 | + dlclose(lib.second.handle); |
| 87 | + #else |
| 88 | +- FreeLibrary(lib.second.handle); |
| 89 | ++ FreeLibrary(static_cast<HMODULE>(lib.second.handle)); |
| 90 | + #endif |
| 91 | + } |
| 92 | + loaded_lib_handled.clear(); |
| 93 | +diff --git a/src/MolaLauncherApp.cpp b/src/MolaLauncherApp.cpp |
| 94 | +index d939bfe..37be9fc 100644 |
| 95 | +--- a/src/MolaLauncherApp.cpp |
| 96 | ++++ b/src/MolaLauncherApp.cpp |
| 97 | +@@ -99,7 +99,7 @@ std::string relative_to_abs_path( |
| 98 | + if (f.is_relative()) |
| 99 | + { |
| 100 | + f = fs::path(*basePath) / f; |
| 101 | +- return f; |
| 102 | ++ return f.string(); // no implicit conversion on Windows (wchar_t paths) |
| 103 | + } |
| 104 | + else |
| 105 | + return path; |
0 commit comments