-
Notifications
You must be signed in to change notification settings - Fork 396
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
Windows: lib import/export macros #480
Comments
"does not make" doesn't mean it is broken. Please share a specific use-case where the old behavior has compilation/runtime issues. If there is such - we'll try to find a backward-compatible solution for all build systems. |
I never claimed that errors occur. But I can also argue the other way around, that just because you haven't had an error yet, it doesn't always have to work. After all, the Windows API provides for the combination of |
You're perfectly right about how things should be in the ideal world. But right now - my strong position is: "don't try to fix what is not broken". And the #480 breaks all windows builds on our CI. |
For what it's worth, I did have problems with that. I linked HIDAPI statically into my DLL, and then noticed that all of its functions were accessible and visible with for example As for the dllimport, Microsoft says it's optional, and only serves to make the compiler generate "more efficient" code, whatever that means (source). So maybe it's not worth it if it is a breaking change. Maybe change the |
That is a very good case. To be able to workaround cases like that I suggest: #ifdef _WIN32
+ #ifndef HID_API_EXPORT
#define HID_API_EXPORT __declspec(dllexport)
+ #endif
#define HID_API_CALL
#else
+ #ifndef HID_API_EXPORT
#define HID_API_EXPORT /**< API export macro */
+ #endif
#define HID_API_CALL /**< API call macro */
#endif and a corresponding define for CMake build of the static library that is not perfect (not even close) but should be good-enough for |
Maybe not the most intuitive, but at least it gives users more flexibility to do what they need without having to change the code itself, and doesn't break anything that currently works. I'd say it's a decent enough compromise. |
Don't mark API functions with __declspec(dllexport) when building a static library on Windows. Enforced by CMake builds. For other builds a compile definition is available. Related: #480
Hi @Youw , On my end, Maybe something like
in hidapi.h would be nice? |
Very interesting. I haven't seen a compiler that would do somehting like that. And only now I took attention into CMake documentation that actually describes that behavior:
Care to share your compiler and its version?
Yes, I guess that should work. |
Have a look at https://github.com/OGRECave/ogre-next/blob/master/OgreMain/include/OgrePlatform.h as a full example for static and dynamic with export and import. A summary is available at https://github.com/Framstag/libosmscout/blob/master/libosmscout/include/osmscout/CoreImportExport.h. Even in the GCC documentation the usage is documented like this https://gcc.gnu.org/wiki/Visibility. The original idea of the proposal was to adapt the import-export API correctly for all cases (static, export, import). Since the simple macro solution is apparently still very unpopular, there is a second way. Simply remove the macro completely and supply a module definition file (https://learn.microsoft.com/en-us/cpp/build/reference/module-definition-dot-def-files?view=msvc-170) for Windows. In CMake it is then relatively simple, everything is identical, only under the Windows DLL this file must be passed to the compiler. The disadvantage of this way is that it only works with Visual Studio and clang under Windows. GCC cannot do this. If you really want to support all compilers in all directions, then you should implement the macro variant. |
I am aware of the the "perfect" solution using macros. And no changes to autotools - those are deprecated, and should stay untouched until removed in v1 (unless obvious bugs, which I'm not aware of). |
@Youw , my cl version is 14.29.30133, came with Visual Studio 2019 Professional.
My bad I was just thinking of a quick fix and didn't give it a thorough enough thought, I'm sure you would come up with a better way to handle this issue at V1 release, looking forward to it! |
I hadn't tested until now, since I haven't touched this part of my code in a while, but indeed I got the same problem. One solution is to define the macro to something explicitly, so it doesn't get implicitly set to 1. This is done in the other empty definitions in the header file itself.
|
The only thing I don't like about this aproach, that the I prefer not to pass "weird" symbols into command-line when I can. |
hidapi/hidapi/hidapi.h
Line 33 in 2b70208
This does not make sense.
dllexport
is normally always used in combination withdllimport
(https://learn.microsoft.com/en-us/cpp/cpp/dllexport-dllimport).The text was updated successfully, but these errors were encountered: