nghttp2
nghttp2 copied to clipboard
nghttp2 static library linkage fails on Windows
Currently, if you compile static libraries with CMake on Windows (via -DBUILD_SHARED_LIBS=off + -DBUILD_STATIC_LIBS=on), the generated nghttp2.h file does not define NGHTTP2_STATICLIB resulting in such errors:
ld.lld: error: undefined symbol: __declspec(dllimport) nghttp2_option_set_no_auto_window_update
>>> referenced by lib/CMakeFiles/libcurl_object.dir/cf-h2-proxy.c.obj:(cf_h2_proxy_connect)
>>> referenced by lib/CMakeFiles/libcurl_object.dir/http2.c.obj:(cf_h2_ctx_init)
...
As a fix, we could add this to CMakeLists.txt
if(BUILD_STATIC_LIBS)
set(NGHTTP2_STATICLIB true)
endif()
and add this line to cmakeconfig.h
#cmakedefine NGHTTP2_STATICLIB
and in nghttp2.h:
#include "config.h"
// ...
#ifdef NGHTTP2_STATICLIB
// works now
# define NGHTTP2_EXTERN
#elif defined(WIN32) || (__has_declspec_attribute(dllexport) && \
__has_declspec_attribute(dllimport))
# ifdef BUILDING_NGHTTP2
# define NGHTTP2_EXTERN __declspec(dllexport)
# else /* !BUILDING_NGHTTP2 */
# define NGHTTP2_EXTERN __declspec(dllimport)
# endif /* !BUILDING_NGHTTP2 */
#else /* !defined(WIN32) */
# ifdef BUILDING_NGHTTP2
# define NGHTTP2_EXTERN __attribute__((visibility("default")))
# else /* !BUILDING_NGHTTP2 */
# define NGHTTP2_EXTERN
# endif /* !BUILDING_NGHTTP2 */
#endif /* !defined(WIN32) */
// ...