Skip to content

cmake: drop redundant -lws2_32 meant for libssh2.pc - #1619

Closed
vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:cm-dupe-ws2_32
Closed

vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:cm-dupe-ws2_32

Conversation

@vszakats

@vszakats vszakats commented Jul 13, 2025 •

Copy link
Copy Markdown
Member

The libssh2.pc generator logic automatically adds -lws2_32 while
parsing LIBSSH2_LIBS, which contains this lib already. Then discard
the duplicate.

This patch introduces a change in the position of ws2_32 within
the lib list advertised via libssh2.pc for static builds.

This order might in cases by significant, but:

For these reasons it seems unlikely this position change could break
Windows OpenSSL static gcc/ld builds relying on libssh2.pc for their
lib list. It least no more than it was before this patch.

Turns out these theories don't stand in practice and the order is broken
possibly by introducing INTERFACE targets, with or without this patch.
libcrypto (tested with LibreSSL) is in fact depending on ws2_32, and
the bcrypt dependency is also causing breakage with picky binutils ld.
I may try addressing it in a separate PR.

Ref: 33b6d5f #827
Ref: 31fb886 #811


Sigh... the amount of wasted time on the binutils ld linker is just
insane. Of course it's broken after the INTERFACE change. Not only
because of crypt32 and bcrypt, but libcrypto (LibreSSL) also
depends on ws2_32 for some reason. ntohl, inet_pton and
even setsockopt.

The `libssh2.pc` generator logic automatically adds `-lws2_32` while
parsing `LIBSSH2_LIBS`, which contains this lib already. Then discard
the duplicate.

This change introduces a change in the position of `ws2_32` within
the lib list.

This order might in cases by significant, but:

- libssh2 no longer links against `libssl`, which was the library
  also referencing `ws2_32` and breaking picky binutils `ld` linker
  when not passed in strict dependency order.
  Ref: c84745e libssh2#1128

- since switching to INTERFACE targets, cmake messes up the lib order
  anyway, adding `OpenSSL:Crypto` last, instead of `ws2_32`. This did
  not seem to cause an issue so far.
  Ref: df0563a libssh2#1535

Ref: 33b6d5f libssh2#827
Ref: 31fb886 libssh2#811
@vszakats vszakats added the build label Jul 13, 2025
@vszakats
vszakats marked this pull request as draft July 13, 2025 12:25
@vszakats
vszakats marked this pull request as ready for review July 13, 2025 12:30
@vszakats vszakats closed this in 22784a5 Jul 13, 2025
@vszakats
vszakats deleted the cm-dupe-ws2_32 branch July 13, 2025 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant