Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-compiling Zig dynamic library from windows-x86_64 to windows-i386 fails to link #9167

Closed
alexrp opened this issue Jun 19, 2021 · 1 comment

Comments

@alexrp
Copy link
Contributor

alexrp commented Jun 19, 2021

$ zig env
{
 "zig_exe": "C:\\Users\\alex\\scoop\\apps\\ziglang\\current\\zig.exe",
 "lib_dir": "C:\\Users\\alex\\scoop\\apps\\ziglang\\current\\lib",
 "std_dir": "C:\\Users\\alex\\scoop\\apps\\ziglang\\current\\lib\\std",
 "global_cache_dir": "C:\\Users\\alex\\AppData\\Local\\zig",
 "version": "0.8.0"
}
$ zig targets | jq .native
{
  "triple": "x86_64-windows.win10_fe...win10_fe-gnu",
  "cpu": {
    "arch": "x86_64",
    "name": "skylake",
    "features": [
      "64bit",
      "adx",
      "aes",
      "avx",
      "avx2",
      "bmi",
      "bmi2",
      "clflushopt",
      "cmov",
      "cx16",
      "cx8",
      "ermsb",
      "f16c",
      "false_deps_popcnt",
      "fast_15bytenop",
      "fast_gather",
      "fast_scalar_fsqrt",
      "fast_shld_rotate",
      "fast_variable_shuffle",
      "fast_vector_fsqrt",
      "fma",
      "fsgsbase",
      "fxsr",
      "idivq_to_divl",
      "invpcid",
      "lzcnt",
      "macrofusion",
      "mmx",
      "movbe",
      "nopl",
      "pclmul",
      "popcnt",
      "prfchw",
      "rdrnd",
      "rdseed",
      "sahf",
      "slow_3ops_lea",
      "sse",
      "sse2",
      "sse3",
      "sse4_1",
      "sse4_2",
      "ssse3",
      "vzeroupper",
      "x87",
      "xsave",
      "xsavec",
      "xsaveopt",
      "xsaves"
    ]
  },
  "os": "windows",
  "abi": "gnu"
}
$ zig libc
# The directory that contains `stdlib.h`.
# On POSIX-like systems, include directories be found with: `cc -E -Wp,-v -xc /dev/null`
include_dir=C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt

# The system-specific include directory. May be the same as `include_dir`.
# On Windows it's the directory that includes `vcruntime.h`.
# On POSIX it's the directory that includes `sys/errno.h`.
sys_include_dir=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include

# The directory that contains `crt1.o` or `crt2.o`.
# On POSIX, can be found with `cc -print-file-name=crt1.o`.
# Not needed when targeting MacOS.
crt_dir=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\x64

# The directory that contains `vcruntime.lib`.
# Only needed when targeting MSVC on Windows.
msvc_lib_dir=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\lib\x64\

# The directory that contains `kernel32.lib`.
# Only needed when targeting MSVC on Windows.
kernel32_lib_dir=C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x64

# The directory that contains `crtbeginS.o` and `crtendS.o`
# Only needed when targeting Haiku.
gcc_dir=
$ touch foo.zig
$ zig build-lib -dynamic -target i386-windows-gnu lib.zig
lld-link: error: <root>: undefined symbol: _DllMainCRTStartup@12
lld-link: error: <root>: undefined symbol: _tls_index
lld-link: error: <root>: undefined symbol: _tls_start
lld-link: error: <root>: undefined symbol: _tls_end
lld-link: error: <root>: undefined symbol: __xl_a
lld-link: error: <root>: undefined symbol: __xl_z
lld-link: error: <root>: undefined symbol: _tls_used
error: LLDReportedFailure

I'm not sure if this is a Zig bug or if I'm just missing some external dependency.

@alexrp
Copy link
Contributor Author

alexrp commented Jul 18, 2021

Appears to be a duplicate of #8531 as disabling LTO makes it work.

@alexrp alexrp closed this as completed Jul 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant