Skip to content

cmake: allow CURL_STATIC_CRT with shared libcurl and no curl exe - #16516

Closed
vszakats wants to merge 2 commits into
curl:masterfrom
vszakats:cm-static-crt-cont
Closed

vszakats wants to merge 2 commits into
curl:masterfrom
vszakats:cm-static-crt-cont

Conversation

@vszakats

@vszakats vszakats commented Feb 28, 2025 •

Copy link
Copy Markdown
Member

Follow-up to edfa537 #16456


Thinking that libcurl.dll users in general might find this combination
working (not crashing) and useful, depending on how they use libcurl.

@vszakats vszakats added cmake Windows Windows-specific labels Feb 28, 2025
@github-actions github-actions Bot added the build label Feb 28, 2025
@vszakats vszakats changed the title cmake: allow CURL_STATIC_CRT with shared libcurl when not building curl exe cmake: allow CURL_STATIC_CRT with shared libcurl and no curl exe Feb 28, 2025
@vszakats vszakats closed this in 049352d Feb 28, 2025
@vszakats
vszakats deleted the cm-static-crt-cont branch February 28, 2025 12:15
vszakats added a commit that referenced this pull request Mar 4, 2025
After this patch, we're back to 8.12.1, but disallowing
`CURL_STATIC_CRT=ON` with shared curl exe built with VS2013 or older.
Because those may crash. A stable reprducer is with `ENABLE_DEBUG=ON`
and calling `curl.exe -V`.

You can pass the necessary CMake and MSVC linker options manually,
to get around this condition.

Shared build with static UCRT may be crashing too, depending on
conditions. Consult the documentation about limitations of static CRT:
https://learn.microsoft.com/cpp/c-runtime-library/crt-library-features

Follow-up to 049352d #16516
Follow-up to edfa537 #16456
Ref: #16394
Closes #16522
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
pps83 pushed a commit to pps83/curl that referenced this pull request Apr 26, 2025
After this patch, we're back to 8.12.1, but disallowing
`CURL_STATIC_CRT=ON` with shared curl exe built with VS2013 or older.
Because those may crash. A stable reprducer is with `ENABLE_DEBUG=ON`
and calling `curl.exe -V`.

You can pass the necessary CMake and MSVC linker options manually,
to get around this condition.

Shared build with static UCRT may be crashing too, depending on
conditions. Consult the documentation about limitations of static CRT:
https://learn.microsoft.com/cpp/c-runtime-library/crt-library-features

Follow-up to 049352d curl#16516
Follow-up to edfa537 curl#16456
Ref: curl#16394
Closes curl#16522
vszakats added a commit that referenced this pull request Oct 16, 2026
Limit this option to static-only curl builds.

Enabling the static CRT for other configurations may successfuly build
them, but executing them do run into nasty problems due to using two CRT
copies at the same time. Also note that the static CRT setting applies
to tests too, which revealed these issues.

Also:
- as it turns out, static CRT may be enabled for non-UCRT builds. After
  this patch, such configuration is possible again.
- note, if these preconditions prevent doing a desired static-CRT build
  variation (e.g. a libcurl.dll built against static CRT). You can
  pass the necessary compiler/linker options via standard CMake options/envs.

I discovered these issues while enabling test runs on AppVeyor CI with
all supported MSVC version in various configurations, and
`-DCURL_STATIC_CRT=ON` set.

Symptoms of double CRT:
- `curl -V` output with newline missing between 'Protocols:' and
  'Features:' lines, then runtests unable to detect feature and emitting
  a Perl warning for uninitialized `$feat` variable. (due to parallel
  output buffering for `puts()` and `curl_mprintf()`)
  This is visible in master builds, e.g.:
  CM VS2019, Debug, x64, OpenSSL 3.0 + Schannel, Shared, !verbose, Build-tests:
  ```

  WARNING: this libcurl is Debug-enabled, do not use in production

  curl 8.23.0-DEV (Windows) libcurl/8.23.0-DEV OpenSSL/3.0.18 (Schannel) WinLDAP
  Release-Date: [unreleased]
  Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps mqtt mqtts pop3 pop3s rtsp smtp smtps telnet tftp ws wssFeatures: alt-svc AsynchDNS Debug HSTS HTTPS-proxy HTTPSIG IPv6 Kerberos Largefile MultiSSL SPNEGO SSL SSPI threadsafe UnixSockets
  ```
  Ref: https://ci.appveyor.com/project/curlorg/curl/builds/54865570/job/urr2rgnr32hwllw2#L246
  Notice the missing newline before `Features:`, and appearing above
  `WARNING:` instead.
- test1622 failing.
- 'Debug Assertion Failed! Expression: _acrt_first_block == header'
  crashed in both the app and the libcurl.dll it loaded. (possibly)

Follow-up to 6140746 #16522
Follow-up to 049352d #16516
Follow-up to edfa537 #16456 #16394
Follow-up to 4fc6ebe #1621
Cherry-picked from #23306

Closes #23336
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

1 participant