MINGW-packages
MINGW-packages copied to clipboard
libcurl static linking error
libcurl give errors with static linking, mingw32
I found that problem with linking nghttp2. It seems that static version libcurl.a linked with dynamic version nghttp2 (i.e. it compiled without flag -DNGHTTP2_STATIC
).
My test CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project(curl_static_test)
add_executable(${PROJECT_NAME} "main.cpp")
add_definitions(-DCURL_STATICLIB)
set(LIBS ${LIBS} curl)
set(LIBS ${LIBS} nghttp2)
set(LIBS ${LIBS} brotlidec-static)
set(LIBS ${LIBS} brotlicommon-static)
set(LIBS ${LIBS} idn2)
set(LIBS ${LIBS} intl)
set(LIBS ${LIBS} unistring)
set(LIBS ${LIBS} iconv)
set(LIBS ${LIBS} ssl)
set(LIBS ${LIBS} crypto)
set(LIBS ${LIBS} ssh2)
set(LIBS ${LIBS} crypt32 z ws2_32 wldap32)
target_link_libraries(${PROJECT_NAME} ${LIBS})
set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")
Got errors like this:
G:\dev\msys32\mingw32\lib\libcurl.a(libcurl_la-http2.o):-1: error: undefined reference to _imp__nghttp2_session_get_stream_user_data
Properly compiled static version libcurl must require _nghttp2_session_get_stream_user_data
.
I am also unable to statically link libcurl
to my projects, which is gonna be an issue since I absolutely need to do static linking for them.
The errors I get with a minimal example are as follows:
undefined reference to `__imp_curl_version_info'
undefined reference to `__imp_curl_easy_setopt'
undefined reference to `__imp_curl_easy_setopt'
undefined reference to `__imp_curl_easy_setopt'
undefined reference to `__imp_curl_easy_setopt'
undefined reference to `__imp_curl_easy_setopt'
more undefined references to `__imp_curl_easy_setopt' follow
undefined reference to `__imp_curl_easy_cleanup'
undefined reference to `__imp_curl_slist_free_all'
undefined reference to `__imp_curl_formfree'
undefined reference to `__imp_curl_easy_init'
undefined reference to `__imp_curl_slist_append'
undefined reference to `__imp_curl_easy_setopt'
undefined reference to `__imp_curl_slist_free_all'
undefined reference to `__imp_curl_easy_setopt'
undefined reference to `__imp_curl_easy_setopt'
undefined reference to `__imp_curl_easy_setopt'
undefined reference to `__imp_curl_easy_setopt'
undefined reference to `__imp_curl_easy_setopt'
more undefined references to `__imp_curl_easy_setopt' follow
undefined reference to `__imp_curl_formadd'
undefined reference to `__imp_curl_easy_setopt'
undefined reference to `__imp_curl_formfree'
undefined reference to `__imp_curl_formadd'
undefined reference to `__imp_curl_easy_setopt'
undefined reference to `__imp_curl_formfree'
undefined reference to `__imp_curl_easy_setopt'
undefined reference to `__imp_curl_easy_setopt'
undefined reference to `__imp_curl_easy_setopt'
undefined reference to `__imp_curl_easy_setopt'
undefined reference to `__imp_curl_easy_setopt'
more undefined references to `__imp_curl_easy_setopt' follow
undefined reference to `__imp_curl_easy_perform'
undefined reference to `__imp_curl_easy_getinfo'
undefined reference to `__imp_curl_easy_getinfo'
undefined reference to `__imp_curl_easy_getinfo'
undefined reference to `__imp_curl_easy_getinfo'
undefined reference to `__imp_curl_slist_free_all'
collect2.exe: error: ld returned 1 exit status
I also tried building libcurl
myself, but I get the exact same errors.
This errors tell that program want to link shared version of libcurl
The question is: why does it want only a dynamic build of libcurl
?
Using curl-config --static-libs
doesn't help in any way.
@williamjcm do you add -static
to link command?
Yes.
EDIT: I'd also like to add this happens whether I use -lcurl
or C:/msys64/mingw64/lib/libcurl.a
in the linking command.
show full linking command
And keep in mind that our project prefer shared linking instead static and this issues is not in our priority in any case
Build command:
i686-w64-mingw32-gcc.exe -Wall -DCURL_STATICLIB -DNGHTTP2_STATICLIB -g -Iinclude -c main.c -o obj\Debug\main.o
i686-w64-mingw32-g++.exe -Llib -o bin\Debug\cb_curl_static.exe obj\Debug\main.o -static-libstdc++ -static-libgcc -static -lcurl -lnghttp2 -lssl -lcrypto -lidn2 -lssh2 -lz -lws2_32 -lwinmm -lwldap32 -lcrypt32 -lintl -lunistring -liconv -lbrotlidec-static -lbrotlicommon-static
Output:
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x47): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x77): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0xaf): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x448): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x4ac): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x5c4): more undefined references to `_imp__nghttp2_session_get_stream_user_data' follow
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x6ee): undefined reference to `_imp__nghttp2_session_want_write'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x760): undefined reference to `_imp__nghttp2_priority_spec_init'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x7e1): undefined reference to `_imp__nghttp2_submit_priority'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x7ee): undefined reference to `_imp__nghttp2_session_send'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x8b3): undefined reference to `_imp__nghttp2_session_del'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x92d): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0xb47): undefined reference to `_imp__nghttp2_submit_rst_stream'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0xb52): undefined reference to `_imp__nghttp2_is_fatal'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0xb69): undefined reference to `_imp__nghttp2_session_get_remote_settings'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0xcea): undefined reference to `_imp__nghttp2_submit_rst_stream'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0xcf3): undefined reference to `_imp__nghttp2_is_fatal'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0xdc7): undefined reference to `_imp__nghttp2_session_set_stream_user_data'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0xe60): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0xeae): undefined reference to `_imp__nghttp2_session_set_stream_user_data'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0xf4d): undefined reference to `_imp__nghttp2_session_want_read'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0xf67): undefined reference to `_imp__nghttp2_session_want_write'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0xfab): undefined reference to `_imp__nghttp2_session_mem_recv'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x105a): undefined reference to `_imp__nghttp2_strerror'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x11d1): undefined reference to `_imp__nghttp2_http2_strerror'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x12a4): undefined reference to `_imp__nghttp2_session_resume_data'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x12c2): undefined reference to `_imp__nghttp2_is_fatal'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x1754): undefined reference to `_imp__nghttp2_submit_request'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x17a3): undefined reference to `_imp__nghttp2_session_send'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x17e1): undefined reference to `_imp__nghttp2_session_resume_data'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x1ce6): undefined reference to `_imp__nghttp2_session_mem_recv'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x1cf3): undefined reference to `_imp__nghttp2_is_fatal'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x1f42): undefined reference to `_imp__nghttp2_strerror'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x1fc7): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x1ff7): undefined reference to `_imp__nghttp2_session_get_stream_user_data'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x20cc): undefined reference to `_imp__nghttp2_version'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x2102): undefined reference to `_imp__nghttp2_http2_strerror'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x2320): undefined reference to `_imp__nghttp2_session_set_stream_user_data'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x235f): undefined reference to `_imp__nghttp2_submit_rst_stream'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x23de): undefined reference to `_imp__nghttp2_session_callbacks_new'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x23fd): undefined reference to `_imp__nghttp2_session_callbacks_set_send_callback'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x2412): undefined reference to `_imp__nghttp2_session_callbacks_set_on_frame_recv_callback'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x2427): undefined reference to `_imp__nghttp2_session_callbacks_set_on_invalid_frame_recv_callback'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x243c): undefined reference to `_imp__nghttp2_session_callbacks_set_on_data_chunk_recv_callback'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x2451): undefined reference to `_imp__nghttp2_session_callbacks_set_before_frame_send_callback'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x2466): undefined reference to `_imp__nghttp2_session_callbacks_set_on_frame_send_callback'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x247b): undefined reference to `_imp__nghttp2_session_callbacks_set_on_frame_not_send_callback'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x2490): undefined reference to `_imp__nghttp2_session_callbacks_set_on_stream_close_callback'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x24a5): undefined reference to `_imp__nghttp2_session_callbacks_set_on_begin_headers_callback'
G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../i686-w64-mingw32/bin/ld.exe: G:/dev/msys32/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/../../../../lib\libcurl.a(libcurl_la-http2.o):(.text+0x24ba): undefined reference to `_imp__nghttp2_session_callbacks_set_on_header_callback'
The full linking command is
x86_64-w64-mingw32-g++.exe -LC:\msys64\mingw64\lib -o bin\Debug\curl_test.exe obj\Debug\main.o -static C:/msys64/mingw64/lib/libcurl.a -pipe -lnghttp2 -lidn2 -lssl -lcrypto -lgdi32 -lcrypt32 -lwldap32 -lbrotlidec-static -lz -lws2_32
I use g++ because all of my current projects are in C++ and have libraries that depend on libcurl
.
@williamjcm Did you set -DCURL_STATICLIB
when building main.c
?
Last output show that it want shared nghttp2, so static libcurl.a is linked with shared llibnghttp2
Yes, and I said about this a few month ago...
@zedxxx as I say if you want to see it fixed maybe you dig into it and create pull request. I have no time... From next month I will not be available for month or two or maybe more. So I will not create and update packages at all.
You just need to add an option -DNGHTTP2_STATIC
in place where you build a static version of libcurl.a.
@zedxxx both static and shared version are build at the same time. So need to dig into configure system and fix it.
nghttp2 looks fine: https://quodlibet.duckdns.org/msys2/package/mingw-w64-x86_64-nghttp2 Probably curl's build system picks wrong lib.
Yes libcurl links with wrong nghttp
I used -DCURL_STATICLIB
, yes. And my main's a cpp
file.
For any interested an alternative cURL library is here:
https://curl.haxx.se/windows
I am using Cygwin so I cant speak to all MSYS2 details, but with my system Brotli, nghttp2 and OpenSSL from the above link are also needed. Here is an example command:
x86_64-w64-mingw32-gcc test.c -DCURL_STATICLIB -static -lcurl \
-lbrotlidec-static -lnghttp2 -lssh2 -lssl -lwldap32 -Wl,--start-group \
-lbcrypt -lbrotlicommon-static -lcrypt32 -lcrypto -lws2_32 -lz
and here are my build scripts:
https://github.com/cup/glade/tree/master/curl
For any interested an alternative cURL library is here:
https://curl.haxx.se/windows
I am using Cygwin so I cant speak to all MSYS2 details, but with my system Brotli, nghttp2 and OpenSSL from the above link are also needed. Here is an example command:
x86_64-w64-mingw32-gcc test.c -DCURL_STATICLIB -static -lcurl \ -lbrotlidec-static -lnghttp2 -lssh2 -lssl -lwldap32 -Wl,--start-group \ -lbcrypt -lbrotlicommon-static -lcrypt32 -lcrypto -lws2_32 -lz
and here are my build scripts:
https://github.com/cup/glade/tree/master/curl
On MSYS, I needed to link the following when downloading libcurl from https://curl.haxx.se/windows
- nghttp2
- ssh2
- ssl
- crypto
- crypt32
- wldap32
- brotlidec-static
- z
- ws2_32
- brotlicommon-static
@muv1 for static linking you have to use pkgconfig to get correct linking libraries.
@muv1 we linking pacman statically with libcurl, so don’t see a problem
@muv1 for shared libraries linker can find what it needs similarly to how ldd
does it:
$ ldd /mingw64/bin/libcurl-4.dll
ntdll.dll => /c/WINDOWS/SYSTEM32/ntdll.dll (0x7ffb98e60000)
KERNEL32.DLL => /c/WINDOWS/System32/KERNEL32.DLL (0x7ffb989d0000)
KERNELBASE.dll => /c/WINDOWS/System32/KERNELBASE.dll (0x7ffb95ef0000)
apphelp.dll => /c/WINDOWS/SYSTEM32/apphelp.dll (0x7ffb93e90000)
ADVAPI32.dll => /c/WINDOWS/System32/ADVAPI32.dll (0x7ffb97a10000)
msvcrt.dll => /c/WINDOWS/System32/msvcrt.dll (0x7ffb98930000)
sechost.dll => /c/WINDOWS/System32/sechost.dll (0x7ffb986f0000)
RPCRT4.dll => /c/WINDOWS/System32/RPCRT4.dll (0x7ffb98330000)
CRYPT32.dll => /c/WINDOWS/System32/CRYPT32.dll (0x7ffb96dc0000)
ucrtbase.dll => /c/WINDOWS/System32/ucrtbase.dll (0x7ffb95df0000)
MSASN1.dll => /c/WINDOWS/System32/MSASN1.dll (0x7ffb95d80000)
WLDAP32.dll => /c/WINDOWS/System32/WLDAP32.dll (0x7ffb98680000)
WS2_32.dll => /c/WINDOWS/System32/WS2_32.dll (0x7ffb98d30000)
libwinpthread-1.dll => /mingw64/bin/libwinpthread-1.dll (0x64940000)
libidn2-0.dll => /mingw64/bin/libidn2-0.dll (0x63d00000)
libbrotlidec.dll => /mingw64/bin/libbrotlidec.dll (0x6e440000)
libnghttp2-14.dll => /mingw64/bin/libnghttp2-14.dll (0x6dc80000)
libpsl-5.dll => /mingw64/bin/libpsl-5.dll (0x6ce40000)
libssh2-1.dll => /mingw64/bin/libssh2-1.dll (0x63b40000)
libssl-1_1-x64.dll => /mingw64/bin/libssl-1_1-x64.dll (0x6d480000)
libcrypto-1_1-x64.dll => /mingw64/bin/libcrypto-1_1-x64.dll (0x67e00000)
USER32.dll => /c/WINDOWS/System32/USER32.dll (0x7ffb98790000)
win32u.dll => /c/WINDOWS/System32/win32u.dll (0x7ffb962d0000)
GDI32.dll => /c/WINDOWS/System32/GDI32.dll (0x7ffb984b0000)
gdi32full.dll => /c/WINDOWS/System32/gdi32full.dll (0x7ffb96c20000)
msvcp_win.dll => /c/WINDOWS/System32/msvcp_win.dll (0x7ffb96ad0000)
libiconv-2.dll => /mingw64/bin/libiconv-2.dll (0x66000000)
libintl-8.dll => /mingw64/bin/libintl-8.dll (0x61cc0000)
zlib1.dll => /mingw64/bin/zlib1.dll (0x62e80000)
libunistring-2.dll => /mingw64/bin/libunistring-2.dll (0x649c0000)
libbrotlicommon.dll => /mingw64/bin/libbrotlicommon.dll (0x70000)
libbrotlicommon.dll => /mingw64/bin/libbrotlicommon.dll (0x70000)
IMM32.DLL => /c/WINDOWS/System32/IMM32.DLL (0x7ffb97ff0000)
Static libs don't have this information so you have to get it from somewhere else. In this case that's pkg-config
:
$ pkg-config --libs --static libcurl
-LD:/msys64/mingw64/lib -lcurl -lnghttp2 -lidn2 -lssh2 -lws2_32 -lpsl -lssl -lcrypto -lssl -lcrypto -lgdi32 -lcrypt32 -lwldap32 -lbrotlidec -lz -lws2_32
I missed that you are using curl-config
.
There are at least 2 issues. Curl build system will search only for dynamic brotli libraries: https://github.com/curl/curl/blob/9a8b3b3e131359aea1cac650fb6ac331fbe2047c/CMake/FindBrotli.cmake#L26-L27 The other issue is brotli since it doesn't generate pkg-conf files for static libraries.
Again, unless someone has a working linker command, my position is and will be that the MSYS2 static LibCurl is broken.
Pacman is linked statically to libcurl so it's not broken but it's not easy to use either.
This issue still exists. Also @nu8, do you still have those alternate build scripts? The link returns a 404.
I successfully compiled a simple c example on my win10 computer with -lcurl -lnghttp2 -lidn2 -lssh2 -lssl -lcrypto -lgdi32 -lcrypt32 -lwldap32 -lbrotlidec -lbrotlienc -lbrotlicommon -lz -lzstd - lgsasl -lws2_32
compiles through a simplest c example. Don't forget to add a #define CURL_STATICLIB
in front of #include <curl/curl.h>
in main.c
, it's important.
I failed at least a hundred times, but this time I succeeded.
I have just refreshed the system to the latest and the issue is resolved. Previously my workaround has been:
Download the pre-built Windows files directly from CURL: https://curl.haxx.se/windows/
Replace the current files.
- Copy curl-
-win32-mingw/lib/libcurl.a -> /mingw32/lib - Copy curl-
-win64-mingw/lib/libcurl.a -> /mingw64/lib
@lzw-723 I get the error
_64-w64-mingw32/bin/ld.exe: cannot find -lgsasl
I installed these libraries: mingw-w64-x86_64-gsasl mingw-w64-i686-gsasl
. But I guess they don't include the library files.
How did you install libgsasl
files in msys?