Skip to content

cc-rs link issue on windows msvc targets when using Clang with GNU cmdline syntax #395

@snailspeed3

Description

@snailspeed3

In particular, the way Corrosion passes the CMake CC_/CXX_ to rust here causes issues when the rust linker attempts to link the binary with the MSVC linker. This affects libcurl_sys and many other -sys crates that use the C compiler Corrosion specifies.

The only change here is switching the target to cdylib (which forces a complete, not partial, link):

  = note:    Creating library C:/Users/rii/Documents/dev/RiiStudio/ws/./cargo/build\x86_64-pc-windows-msvc\release\deps\riistudio_rs.dll.lib and object C:/Users/rii/Documents/dev/RiiStudio/ws/./cargo/build\x86_64-pc-windows-msvc\release\deps\riistudio_rs.dll.exp
          libcurl_sys-7b6cbe17349096cb.rlib(digest_sspi.o) : error LNK2001: unresolved external symbol strdup
          libcurl_sys-7b6cbe17349096cb.rlib(vauth.o) : error LNK2001: unresolved external symbol strdup
          ...
          libcurl_sys-7b6cbe17349096cb.rlib(rename.o) : error LNK2001: unresolved external symbol strdup
          libcurl_sys-7b6cbe17349096cb.rlib(warnless.o) : error LNK2019: unresolved external symbol read referenced in function curlx_read
          libcurl_sys-7b6cbe17349096cb.rlib(warnless.o) : error LNK2019: unresolved external symbol write referenced in function curlx_write
          ...

A run with this issue can be seen here from this commit.

There are a few workarounds I've found:

  • Switch to clang-cl (not viable)
  • Avoid libraries like libcurl_sys (not viable)
  • Manually pass the MSVC compiler as CC to override CC_ (hacky)
  • Disable passing CC_ altogether (hacky, but works and seen here and fixes the build on CI seen above with this CI commit and CI run)

I believe the least annoying solution would be a flag to disable setting the CC_ rustflag altogether, and let rust use the system compiler directly. Alternatively, it seems if we want to pass CC, we may also need to pass the linker, though that appears less feasible.

Cheers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions