Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building on Windows creates __stdcall-convention static lib/dll regardless of compiler settings #722

Closed
trollcop opened this issue Mar 10, 2016 · 3 comments

Comments

@trollcop
Copy link

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.

@stweil
Copy link
Contributor

stweil commented Mar 10, 2016

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.

Non-Windows targets are not affected at all.

@trollcop
Copy link
Author

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).

@mayeut
Copy link
Collaborator

mayeut commented Jul 13, 2016

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.

@trollcop trollcop closed this as completed Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants