From c8988ffd66c527de493fd23c5f9fca65944fbe29 Mon Sep 17 00:00:00 2001 From: Kaz Nishimura Date: Tue, 28 Jan 2020 20:21:22 +0900 Subject: [PATCH 1/4] Enable 'win32-dll' in libtool --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 9d6bb92..3107fd9 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ AC_CONFIG_SRCDIR([libcppunitx/registry.cpp]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIRS([m4]) LT_PREREQ([2.4.6]) -LT_INIT([dlopen]) +LT_INIT([dlopen win32-dll]) AM_INIT_AUTOMAKE([foreign no-define]) AC_PROG_CC AC_PROG_CXX From 848d7f3415aac6ec643eeaa5f2a82f608baaf33b Mon Sep 17 00:00:00 2001 From: Kaz Nishimura Date: Sat, 12 Dec 2020 15:05:08 +0900 Subject: [PATCH 2/4] Include --- libcppunitx/module_loader.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libcppunitx/module_loader.cpp b/libcppunitx/module_loader.cpp index 3f2902b..b1ae24a 100644 --- a/libcppunitx/module_loader.cpp +++ b/libcppunitx/module_loader.cpp @@ -20,6 +20,11 @@ #include #endif +#if _WIN32 +#define WIN32_LEAN_AND_MEAN 1 +#include +#endif + #include "module_loader.h" #if HAVE_DLFCN_H From 3752862ba58d9b9b66a626e6ccbd23fff07e3f12 Mon Sep 17 00:00:00 2001 From: Kaz Nishimura Date: Sat, 12 Dec 2020 15:13:42 +0900 Subject: [PATCH 3/4] Add a configuration for the MinGW-w64 cross-compiler --- .vscode/c_cpp_properties.json | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 322e727..42e5a73 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -19,6 +19,25 @@ "limitSymbolsToIncludedHeaders": true } }, + { + "name": "Win32 (MinGW-w64 cross)", + "compilerPath": "i686-w64-mingw32-gcc", + "includePath": [ + "${workspaceFolder}", + "${workspaceFolder}/libcppunitx" + ], + "defines": [ + "HAVE_CONFIG_H" + ], + "cStandard": "c11", + "cppStandard": "c++11", + "browse": { + "path": [ + "${workspaceFolder}" + ], + "limitSymbolsToIncludedHeaders": true + } + }, { "name": "Win32 (MSVC)", "intelliSenseMode": "msvc-x64", From 29d22b35e76e0a4d6cce688d55eae283dcd04531 Mon Sep 17 00:00:00 2001 From: Kaz Nishimura Date: Sat, 12 Dec 2020 16:42:01 +0900 Subject: [PATCH 4/4] Add code to load modules on Windows --- libcppunitx/module_loader.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libcppunitx/module_loader.cpp b/libcppunitx/module_loader.cpp index b1ae24a..996dfb1 100644 --- a/libcppunitx/module_loader.cpp +++ b/libcppunitx/module_loader.cpp @@ -113,24 +113,31 @@ void module::open(const char *const name) close(); #if HAVE_DLFCN_H _native_handle = dlopen(name, RTLD_LAZY); +#elif _WIN32 + _native_handle = LoadLibraryA(name); #endif } void module::close() { -#if HAVE_DLFCN_H native_handle_type handle = nullptr; std::swap(_native_handle, handle); if (handle != nullptr) { +#if HAVE_DLFCN_H dlclose(handle); - } +#elif _WIN32 + FreeLibrary(static_cast(handle)); #endif + } } void *module::sym(const char *symbol) { #if HAVE_DLFCN_H return dlsym(_native_handle, symbol); +#elif _WIN32 + return reinterpret_cast( + GetProcAddress(static_cast(_native_handle), symbol)); #else return nullptr; #endif