You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know what is default calling convention on Lunix, but Cmake-GUI-generated Visual Studio project files are set to __cdecl. As a result of using OPJ_CALLCONV, all the exported functions end up __stdcall (something like func_name@2 when exported in DLL) and thus cannot be linked to from any __cdecl code.
Anyway, since I have no idea how this affects non-Windows builds, I'm just going to leave this out there. The fix was obviously to simply #define OPJ_CALLCONV to be a blank - remove __stdcall.
I'm also not sure the logic in #if defined(OPJ_STATIC) || !defined(_WIN32) is correct?
Anyway, I've managed to build static win32 libs for my project and they work OK.
The text was updated successfully, but these errors were encountered:
Why should it not be possible to call a __stdcall function from __cdecl code? AFAIK __stdcall is commonly used for exported functions of Windows DLLs, and of course they can be called (otherwise it would be impossible to use a DLL) - you only need the correct declaration, then the compiler knows how to handle mixtures of different calling conventions. There is nothing wrong in using __stdcall for openjpeg, too.
I don't know why it makes a difference, but my project (which uses openjpeg) and openjpeg project itself were both set to __cdecl in compiler properties.
But, I think, what happens is __stdcall - functions without .def file results in exported names being slightly mangled (like I said, _func_name@2 instead of just _func_name) in dll/lib exports. So the resulting .lib and/or .lib+dll cannot be linked by a __cdecl project. I can't think of any reason to mix calling conventions inside same library, and since this doesn't affect anything except windows, maybe just blanking OPJ_CALLCONV for all targets, and then Windows people can change convention from the Visual Studio project (if they really require it at all).
As @stweil said, there's nothing wrong with using __stdcall. The only issue I can see is the opposite problem: someones changes the default compiler setting (let's say __stdcall) in their project & defines OPJ_STATIC to link with a static library that was built with default settings.
So if I had to do anything, it would be to force a calling convention even for static library.
The culprit is here:
https://github.com/uclouvain/openjpeg/blob/master/src/lib/openjp2/openjpeg.h#L94
I don't know what is default calling convention on Lunix, but Cmake-GUI-generated Visual Studio project files are set to __cdecl. As a result of using OPJ_CALLCONV, all the exported functions end up __stdcall (something like func_name@2 when exported in DLL) and thus cannot be linked to from any __cdecl code.
Anyway, since I have no idea how this affects non-Windows builds, I'm just going to leave this out there. The fix was obviously to simply #define OPJ_CALLCONV to be a blank - remove __stdcall.
I'm also not sure the logic in #if defined(OPJ_STATIC) || !defined(_WIN32) is correct?
Anyway, I've managed to build static win32 libs for my project and they work OK.
The text was updated successfully, but these errors were encountered: