msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.21k stars 1.18k forks source link

Linking curl broken since roughly 2 days ago #21028

Open ReenigneArcher opened 3 weeks ago

ReenigneArcher commented 3 weeks ago

Description / Steps to reproduce the issue

Curl is failing to statically link since ~2 days ago.

  1. Install mingw-w64-ucrt-x86_64-curl
  2. Find curl like: https://github.com/LizardByte/Sunshine/blob/f0a00ae35683dfd5742952fb4cf99edf268b57fd/cmake/dependencies/common.cmake#L16
  3. Statically link curl like: https://github.com/LizardByte/Sunshine/blob/f0a00ae35683dfd5742952fb4cf99edf268b57fd/cmake/compile_definitions/windows.cmake#L15-L18
  4. Include curl like: https://github.com/LizardByte/Sunshine/blob/f0a00ae35683dfd5742952fb4cf99edf268b57fd/cmake/compile_definitions/common.cmake#L140
  5. Final link: https://github.com/LizardByte/Sunshine/blob/f0a00ae35683dfd5742952fb4cf99edf268b57fd/cmake/targets/common.cmake#L25

Expected behavior

Curl properly links as it did previously.

Actual behavior

The initial error (~2 days ago) was many undefined references (https://github.com/LizardByte/Sunshine/actions/runs/9278791852/job/25530652407?pr=2604#step:7:501)

[ 81%] Linking CXX executable sunshine.exe
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x430): undefined reference to `__imp_nghttp3_conn_read_stream'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x5a2): undefined reference to `__imp_nghttp3_strerror'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x69a): undefined reference to `__imp_nghttp3_conn_close_stream'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x73a): undefined reference to `__imp_nghttp3_conn_close_stream'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x75c): undefined reference to `__imp_nghttp3_strerror'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x880): undefined reference to `__imp_nghttp3_conn_resume_stream'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x95d): undefined reference to `__imp_nghttp3_conn_shutdown_stream_read'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x973): undefined reference to `__imp_nghttp3_conn_close_stream'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x986): undefined reference to `__imp_nghttp3_conn_set_stream_user_data'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0xe4d): undefined reference to `__imp_nghttp3_rcbuf_get_buf'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x1fe0): undefined reference to `__imp_nghttp3_conn_writev_stream'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x228d): undefined reference to `__imp_nghttp3_conn_block_stream'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x2335): undefined reference to `__imp_nghttp3_conn_add_write_offset'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x235f): undefined reference to `__imp_nghttp3_conn_add_ack_offset'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x2597): undefined reference to `__imp_nghttp3_strerror'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x25d3): undefined reference to `__imp_nghttp3_strerror'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x25ef): undefined reference to `__imp_nghttp3_strerror'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x2721): undefined reference to `__imp_nghttp3_conn_unblock_stream'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x29e1): undefined reference to `__imp_nghttp3_conn_resume_stream'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x2f44): undefined reference to `__imp_nghttp3_conn_del'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x3848): undefined reference to `__imp_nghttp3_conn_submit_request'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x39db): undefined reference to `__imp_nghttp3_conn_resume_stream'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x3deb): undefined reference to `__imp_nghttp3_strerror'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x4a19): undefined reference to `__imp_nghttp3_settings_default_versioned'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x4a1f): undefined reference to `__imp_nghttp3_mem_default'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x4a50): undefined reference to `__imp_nghttp3_conn_client_new_versioned'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x4ba9): undefined reference to `__imp_nghttp3_conn_bind_control_stream'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x4bd1): undefined reference to `__imp_nghttp3_conn_bind_qpack_streams'
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(libcurl_la-curl_osslq.o):(.text+0x4fb0): undefined reference to `__imp_nghttp3_version'
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [CMakeFiles\sunshine.dir\build.make:836: sunshine.exe] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:214: CMakeFiles/sunshine.dir/all] Error 2
mingw32-make[1]: *** Waiting for unfinished jobs....

But now it is many multiple definition (https://github.com/LizardByte/Sunshine/actions/runs/9278791852/job/25604282363?pr=2604#step:7:504)

[ 84%] Linking CXX executable sunshine.exe
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(unity_0_c.c.obj):(.text+0x3e80): multiple definition of `get_dll_path'; D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcrypto.a(libcrypto-lib-pathtools.obj):(.text+0x0): first defined here
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(unity_0_c.c.obj):(.text+0x3e850): multiple definition of `sanitise_path'; D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcrypto.a(libcrypto-lib-pathtools.obj):(.text+0x190): first defined here
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(unity_0_c.c.obj):(.text+0x3e8d0): multiple definition of `simplify_path'; D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcrypto.a(libcrypto-lib-pathtools.obj):(.text+0x210): first defined here
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(unity_0_c.c.obj):(.text+0x3ebf0): multiple definition of `get_relative_path'; D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcrypto.a(libcrypto-lib-pathtools.obj):(.text+0x510): first defined here
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(unity_0_c.c.obj):(.text+0x3f110): multiple definition of `get_executable_path'; D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcrypto.a(libcrypto-lib-pathtools.obj):(.text+0x9b0): first defined here
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(unity_0_c.c.obj):(.text+0x3f1f0): multiple definition of `strip_n_suffix_folders'; D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcrypto.a(libcrypto-lib-pathtools.obj):(.text+0xa70): first defined here
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(unity_0_c.c.obj):(.text+0x3f240): multiple definition of `get_relocated_path_list'; D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcrypto.a(libcrypto-lib-pathtools.obj):(.text+0xac0): first defined here
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(unity_0_c.c.obj):(.text+0x3f2b0): multiple definition of `get_relocated_path_list_lib'; D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcrypto.a(libcrypto-lib-pathtools.obj):(.text+0xb00): first defined here
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(unity_0_c.c.obj):(.text+0x3f370): multiple definition of `single_path_relocation'; D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcrypto.a(libcrypto-lib-pathtools.obj):(.text+0xb90): first defined here
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(unity_0_c.c.obj):(.text+0x3f440): multiple definition of `single_path_relocation_lib'; D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcrypto.a(libcrypto-lib-pathtools.obj):(.text+0xca0): first defined here
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(unity_0_c.c.obj):(.text+0x3f560): multiple definition of `msys2_get_relocated_single_path'; D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcrypto.a(libcrypto-lib-pathtools.obj):(.text+0xdf0): first defined here
D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcurl.a(unity_0_c.c.obj):(.text+0x3f6d0): multiple definition of `msys2_get_relocated_path_list'; D:/a/_temp/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../lib\libcrypto.a(libcrypto-lib-pathtools.obj):(.text+0xf20): first defined here
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [CMakeFiles\sunshine.dir\build.make:836: sunshine.exe] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:214: CMakeFiles/sunshine.dir/all] Error 2
mingw32-make[1]: *** Waiting for unfinished jobs....

Verification

Windows Version

Microsoft Windows Server 2019, 10.0.17763 (GitHub hosted runner)

MINGW environments affected

Are you willing to submit a PR?

I would if I knew what the fix was.

Biswa96 commented 3 weeks ago

I wonder if cmake unity build causes the multiple definition issue - the same path relocation symbols come from openssl and curl.

Biswa96 commented 3 weeks ago

The undefined reference issue can be fixed with proper compiler flags -DNGHTTP2_STATICLIB -DNGHTTP3_STATICLIB. I think those should be handled by pkgconfig file and shall do some experiments.

ReenigneArcher commented 3 weeks ago

Thanks for looking into this so quickly, much appreciated!

mariotaku commented 3 weeks ago

There are another issue causing broken linkage: both libcrypto.a and libcurl.a are having objects from pathtools.c. #5074 #8955

If someone is statically linking those libraries, what's the best way to ignore the duplicated symbols?

Biswa96 commented 3 weeks ago

There are another issue causing broken linkage: both libcrypto.a and libcurl.a are having objects from pathtools.c

Yeah, I have provided the same reason above but I can not reproduce that issue with simple program. The following command compiles a example program statically linked with curl library.

 cc -static $(pkgconf -cflags -static libcurl) curl-8.8.0/docs/examples/simple.c $(pkgconf -libs -static libcurl) -lws2_32 -lz

It requires the pkgconfig changes as provided in the linked pull request.

Static linking reveals another issue. I can not run the statically compiled program.

$ ./a.exe
curl_easy_perform() failed: Problem with the SSL CA cert (path? access rights?)

Probably path relocation does not work with static linking.

Biswa96 commented 3 weeks ago

lazka, could the multiple definition issue be fixed if pathtools.c functions are moved to pathtools.h and are made static?

mariotaku commented 3 weeks ago

@Biswa96 I think this will work.

Biswa96 commented 3 weeks ago

I have fixed the undefined references issue with fixes in pkgconfig files and can not reproduce the multiple definition error with simple curl example. Please wait for others to fix it.

kmilos commented 3 weeks ago

Still getting

undefined reference to `__imp_curl_easy_setopt'

w/ mingw-w64-curl-8.8.0-8

Biswa96 commented 3 weeks ago

Is CURL_STATICLIB macro defined?

kmilos commented 3 weeks ago

Is CURL_STATICLIB macro defined?

Looks like only in the expected *_STATIC_CFLAGS in my CMake cache...

saghul commented 3 weeks ago

Seeing the same problem when linking an application with libcurl. -2 worked, -8 fails wit the above error.

Biswa96 commented 3 weeks ago

Could you reproduce the issue with a minimal example with CURL_STATICLIB macro defined for static linking? That symbol does exist in both static library and import library.

$ nm /ucrt64/lib/libcurl.dll.a | grep curl_easy_setopt
0000000000000000 I __imp_curl_easy_setopt
0000000000000000 T curl_easy_setopt

$ nm /ucrt64/lib/libcurl.a | grep curl_easy_setopt
0000000000081d40 T curl_easy_setopt
saghul commented 3 weeks ago

But I don't want to link statically 😅 Or is it expected that applications always statically link to libcurl now?

Biswa96 commented 3 weeks ago

is it expected that applications always statically link to libcurl now?

No, it is not expected. This issue is about static linking so I assumed that. Could you compile this example program? https://github.com/curl/curl/blob/curl-8_8_0/docs/examples/simple.c It uses curl_easy_setopt function.

saghul commented 3 weeks ago

No I am using a more complex application.

I solved it as follows: instead of adding CURL_LIBS to my target's link libraries, I now link with CURL::libcurl

While that works, it was surprising that it broke out of the blue.

Now I do think this way is more correct, so I did learn something new today!

Biswa96 commented 3 weeks ago

I solved it as follows: instead of adding CURL_LIBS to my target's link libraries, I now link with CURL::libcurl

That could be due to migration from autotools to cmake which is not related to this issue. See this commit https://github.com/msys2/MINGW-packages/commit/db8fd75ce7834f456a2dbf832c3751d0ce04993e

saghul commented 3 weeks ago

Interesting! It was certainly that in my case, hopefully it can help others if they run into it and find this issue. Cheers!

kmilos commented 3 weeks ago

Confirming that -2 worked, and -7 doesn't for shared library linking, and requires the switch to CURL::libcurl target instead of CURL_LIBRARIES. IMHO both should still work for shared linking.

AlynxZhou commented 3 weeks ago

-7 doesn't for shared library linking, and requires the switch to CURL::libcurl target instead of CURL_LIBRARIES.

When building cURL with CMake, it will generates a CURLConfig.cmake config which could be used by find_package(), and this won't set CURL_LIBRARIES like the FindCURL.cmake module, so you need to set(CURL_LIBRARIES CURL::libcurl) or find_package(CURL MODULE).

See <https://cmake.org/cmake/help/book/mastering-cmake/chapter/Finding Packages.html>.

UPDATE: find_package(CURL MODULE) won't work, because https://cmake.org/cmake/help/latest/module/FindCURL.html#curl-cmake. Scary logic, when I say module, I am not meaning config, why they are doing such scary thing?

kmilos commented 3 weeks ago

When building cURL with CMake...

That's besides the point - a client app can't possibly know how curl was built a priori, so this change in behaviour is not welcome.

MehdiChinoune commented 3 weeks ago

FindCURL CMake builtin module already defines an IMPORTED Module CURL::libcurl

New in version 3.12.

This module defines IMPORTED target CURL::libcurl, if curl has been found.

Also:

New in version 3.17.

If CURL was built using the CMake buildsystem then it provides its own CURLConfig.cmake
file for use with the find_package() command's config mode.
This module looks for this file and, if found, returns its results with no further action.

Set CURL_NO_CURL_CMAKE to ON to disable this search.
kmilos commented 3 weeks ago

I get all that. Still saying CURL_LIBRARIES shouldn't have broken, as FindCURL still claims it will produce a valid one, regardless of how curl was built:

CURL_LIBRARIES
    List of libraries when using curl.
MehdiChinoune commented 3 weeks ago

I get all that. Still saying CURL_LIBRARIES shouldn't have broken, as FindCURL still claims it will produce a valid one, regardless of how curl was built:

CURL_LIBRARIES
    List of libraries when using curl.

Report the issue to CMake.

kmilos commented 3 weeks ago

Report the issue to CMake.

Looks like we're not the first to notice:

https://gitlab.kitware.com/cmake/cmake/-/issues/24580 https://gitlab.kitware.com/cmake/cmake/-/issues/25994

vszakats commented 2 weeks ago

For the duplicate symbols one solution is to add this line to lib/CMakeLists.txt, as part of 0001-Make-cURL-relocatable.patch:

set_source_files_properties(pathtools.c PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON)

As for the missing __imp_* libcurl symbols and CURL_LIBRARIES left empty, here's a patch proposal that may help: https://github.com/curl/curl/pull/13897

ReenigneArcher commented 1 week ago

Just to add, I am statically linking curl which has slightly different variable names, like:

@vszakats would your PR to curl handle these as well?

vszakats commented 1 week ago

@ReenigneArcher No. Are these variables also filled by CMake's FindCURL.cmake?

ReenigneArcher commented 1 week ago

@vszakats Accoring to https://cmake.org/cmake/help/latest/module/FindCURL.html, no.

We're using pkg_check_modules(CURL REQUIRED libcurl) which does populate them.

vszakats commented 1 week ago

@vszakats Accoring to https://cmake.org/cmake/help/latest/module/FindCURL.html, no.

We're using pkg_check_modules(CURL REQUIRED libcurl) which does populate them.

Ah okay, that looks like a different problem.

This other PR may help with the above: https://github.com/curl/curl/pull/13911