randy408 / libspng

Simple, modern libpng alternative
https://libspng.org
BSD 2-Clause "Simplified" License
742 stars 75 forks source link

Error linking libspng functions when compiling Mingw-w64 project #254

Closed native-engine closed 1 year ago

native-engine commented 1 year ago

The libspng library itself compiles under Mingw-w64 without any problems, but when compiling under Mingw-w64 of my project, the compiler displays a link error for library functions:

undefined reference to `__imp_spng_ctx_new'
undefined reference to `__imp_spng_set_option'
undefined reference to `__imp_spng_set_ihdr'
undefined reference to `__imp_spng_encode_image'
undefined reference to `__imp_spng_get_png_buffer'
undefined reference to `__imp_spng_ctx_free'

Under GCC, my project compiles with libspng without problems.

randy408 commented 1 year ago

Are building with CMake or Meson?

native-engine commented 1 year ago

CMake with this file: https://gist.github.com/peterspackman/8cf73f7f12ba270aa8192d6911972fe8

randy408 commented 1 year ago

When symbols start with __imp_ it's looking for symbols in a dynamic library, if those aren't found then you're probably linking against the static version but SPNG_STATIC is not defined. The build definition does add that define for spng_static so i'm not sure what's going on, are you not using CMake when linking?

native-engine commented 1 year ago

Added SPNG_STATIC definition before including header, now everything is compiled without problems. Thank you!