ebiggers / libdeflate

Heavily optimized library for DEFLATE/zlib/gzip compression and decompression

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Users of libdeflate shouldn't require to define LIBDEFLATE_STATIC or somehting like that.

pps83 opened this issue · comments

On Windows, you must define LIBDEFLATE_STATIC if you are linking to the static library version of libdeflate instead of the DLL.

Pretty unusual requirement. Should be removed imo, libdeflate didn't have that in older versions afaik. Even if you link to dll version, and if you you define LIBDEFLATE_STATIC it will still link and work ok.
I'm not 100%, but afaik, there is minor advantage when you declare dllimport - functions from dlls avoid indirection or something like that. In case of libdeflate it's hardly relevant. I'd suggest to completely remove it:

#ifndef LIBDEFLATEEXPORT
#define LIBDEFLATEEXPORT
#endif

when building, inside lib src code you'd define it to:

if msvc && dll:
  define LIBDEFLATEEXPORT dllexport
else if gcc:
  define LIBDEFLATEEXPORT visibility default

* On Windows, you must define LIBDEFLATE_STATIC if you are linking to the

Well, it used to be LIBDEFLATE_DLL to use the DLL, but that didn't work well with pkg-config (#229) so I changed it to LIBDEFLATE_STATIC to use the static library. Lots of libraries use one method or the other, so it's not unusual.

That being said, if dllimport is really not necessary we could drop it. I was not aware that was possible. Is there any document that describes the best practices here?

Well, it used to be LIBDEFLATE_DLL to use the DLL, but that didn't work well with pkg-config (#229) so I changed it to LIBDEFLATE_STATIC to use the static library. Lots of libraries use one method or the other, so it's not unusual.

That being said, if dllimport is really not necessary we could drop it. I was not aware that was possible. Is there any document that describes the best practices here?

https://gcc.gnu.org/wiki/Visibility last section there tells how to properly do it.

about dllimpotr: https://stackoverflow.com/questions/8863193/what-does-declspecdllimport-really-mean in short, " This is a code size and speed optimisation". It's irrelevant for libdeflate

https://gcc.gnu.org/wiki/Visibility last section there tells how to properly do it.

Well, that actually says to use dllimport.

Anyway, #263 brings back LIBDEFLATE_DLL but makes it clear that it is optional.

I'd suggest to also do something similar to what I've done in my local copy:

Clean up LIBDEFLATEEXPORT/LIBDEFLATEAPI mess