From ac3e6ce11346e55af4c71b1c9bc9f9c54bc2f5a0 Mon Sep 17 00:00:00 2001 From: ptahmose Date: Tue, 15 Oct 2024 04:24:14 +0200 Subject: [PATCH] Improve Windows compatibility and function exports Comment out static linking options in CMakeLists.txt. Add Windows-specific includes and DllMain definition in DllMain.cpp. Define DLLEXPORT macro in exportedfunctions.cpp for cross-compiler compatibility. --- libmexlibczi/CMakeLists.txt | 2 +- libmexlibczi/DllMain.cpp | 2 ++ libmexlibczi/exportedfunctions.cpp | 12 +++++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libmexlibczi/CMakeLists.txt b/libmexlibczi/CMakeLists.txt index 9a51670..db75437 100644 --- a/libmexlibczi/CMakeLists.txt +++ b/libmexlibczi/CMakeLists.txt @@ -17,6 +17,6 @@ if(WIN32) #set_target_properties(MatlabCZI PROPERTIES SUFFIX ".mexw64") elseif(UNIX) #set_target_properties(MatlabCZI PROPERTIES SUFFIX ".mexa64") - target_link_options(libmexlibczi PRIVATE -static-libgcc -static-libstdc++ ) + #target_link_options(libmexlibczi PRIVATE -static-libgcc -static-libstdc++ ) set_target_properties(MatlabCZI PROPERTIES PREFIX "") # otherwise "lib" is prepended endif() \ No newline at end of file diff --git a/libmexlibczi/DllMain.cpp b/libmexlibczi/DllMain.cpp index b9c475f..95630c1 100644 --- a/libmexlibczi/DllMain.cpp +++ b/libmexlibczi/DllMain.cpp @@ -1,3 +1,4 @@ +#if _WIN32 #include BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) @@ -23,3 +24,4 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv return TRUE; } +#endif \ No newline at end of file diff --git a/libmexlibczi/exportedfunctions.cpp b/libmexlibczi/exportedfunctions.cpp index 02dd50a..51b3e19 100644 --- a/libmexlibczi/exportedfunctions.cpp +++ b/libmexlibczi/exportedfunctions.cpp @@ -1,16 +1,22 @@ #include -extern "C" __declspec(dllexport) void mexFunction(int nlhs, Parameter plhs[], int nrhs, const Parameter prhs[], IAppExtensionFunctions* app_functions) +#ifdef __GNUC__ +#define DLLEXPORT __attribute__((visibility("default"))) +#else +#define DLLEXPORT __declspec(dllexport) +#endif + +extern "C" DLLEXPORT void mexFunction(int nlhs, Parameter plhs[], int nrhs, const Parameter prhs[], IAppExtensionFunctions* app_functions) { mexlibCZI::mexFunction(nlhs, plhs, nrhs, prhs, app_functions); } -extern "C" __declspec(dllexport) void OnInitialize() +extern "C" DLLEXPORT void OnInitialize() { mexlibCZI::OnInitialize(); } -extern "C" __declspec(dllexport) void OnShutdown() +extern "C" DLLEXPORT void OnShutdown() { mexlibCZI::OnShutdown(); }