Skip to content

Commit

Permalink
Improve Windows compatibility and function exports
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ptahmose committed Oct 15, 2024
1 parent 9cf2a46 commit ac3e6ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libmexlibczi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 2 additions & 0 deletions libmexlibczi/DllMain.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if _WIN32
#include <Windows.h>

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
Expand All @@ -23,3 +24,4 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv

return TRUE;
}
#endif
12 changes: 9 additions & 3 deletions libmexlibczi/exportedfunctions.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#include <include/function.h>

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();
}

0 comments on commit ac3e6ce

Please sign in to comment.