hobuinc/laz-perf

LAZPERF_EXPORT macro is wrong on Windows

SpaceIm opened this issue · 5 comments

LAZPERF_EXPORT macro is defined in lazperf.h: https://github.com/hobu/laz-perf/blob/2e3c316248fa534cdeba1b47b2e9fe1a0ecf5dca/cpp/lazperf/lazperf.hpp#L42-L47

It's broken on Windows.

  • If static, this macro should be empty (all OS)
  • If shared, this macro should be:
    • Windows: __declspec(dllexport) at build time, and __declspec(dllimport) at consume time
    • others OS: __attribute__((visibility ("default")))

What specific problem is the current code causing? What errors/failures are occurring?

I've not tested yet, I'm packaging laz-perf for conan, but I already know it's a wrong logic, probably leading to undefined references or lot of warnings.

The logic should be something like this:

#ifdef LAZPERF_SHARED
#  ifdef _WIN32
#    ifdef LAZPERF_BUILD
#      define LAZPERF_EXPORT __declspec(dllexport)
#    else
#      define LAZPERF_EXPORT __declspec(dllimport)
#    endif
#  else
#    define LAZPERF_EXPORT __attribute__((visibility ("default")))
#  endif
#else
#  define LAZPERF_EXPORT
#endif

Then in CMakeLists.txt in lazperf subfolder:

    target_compile_definitions(${LAZPERF_SHARED_LIB} PRIVATE LAZPERF_BUILD PUBLIC LAZPERF_SHARED)

I changed things so that the installed code will, by default, offer __declspec(dllimport), not that it matters much.