Skip to content

[MSVC] Referencing a static from another crate doesn't seem to work #26591

Closed
@tomaka

Description

@tomaka

The glutin library has a build script and the khronos_api build-dependency.
The khronos_api crate does nothing except export 4 pub static items (source code here).

This build script fails to compile with the MSVC++ nightlies with the following error:

     Running `rustc build.rs --crate-name build_script_build --crate-type bin -C prefer-dynamic -g --cfg feature="default" --cfg feature="window" --out-dir C:\projects\glutin\target\debug\build\glutin-40bab6d10148d98f --emit=dep-info,link -L dependency=C:\projects\glutin\target\debug -L dependency=C:\projects\glutin\target\debug\deps --extern gl_generator=C:\projects\glutin\target\debug\deps\libgl_generator-3f3da0d671af0734.rlib --extern khronos_api=C:\projects\glutin\target\debug\deps\libkhronos_api-af8e40aff286ad52.rlib`
error: linking with `link.exe` failed: exit code: 1120
note: "link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\projects\glutin\rustc-nightly-x86_64-pc-windows-msvc\rustc\bin\rustlib\x86_64-pc-windows-msvc\lib" "C:\projects\glutin\target\debug\build\glutin-40bab6d10148d98f\build_script_build.o" "/OUT:C:\projects\glutin\target\debug\build\glutin-40bab6d10148d98f\build_script_build.exe" "/OPT:REF,ICF" "C:\projects\glutin\target\debug\deps\libgl_generator-3f3da0d671af0734.rlib" "C:\projects\glutin\target\debug\deps\libxml-b8f632f5409f1c24.rlib" "C:\projects\glutin\target\debug\deps\libkhronos_api-af8e40aff286ad52.rlib" "C:\projects\glutin\target\debug\deps\liblog-8a6aba167994951e.rlib" "C:\projects\glutin\target\debug\deps\liblibc-ef5cbad4ef5c7a1e.rlib" "C:\projects\glutin\target\debug\deps\libbitflags-52cb4de1e3db33a5.rlib" "/LIBPATH:C:\projects\glutin\rustc-nightly-x86_64-pc-windows-msvc\rustc\bin\rustlib\x86_64-pc-windows-msvc\lib" "std-74fa456f.lib" "/LIBPATH:C:\projects\glutin\target\debug" "/LIBPATH:C:\projects\glutin\target\debug\deps" "/LIBPATH:C:\projects\glutin\rustc-nightly-x86_64-pc-windows-msvc\rustc\bin\rustlib\x86_64-pc-windows-msvc\lib" "/LIBPATH:C:\projects\glutin\.rust\bin\x86_64-pc-windows-msvc" "/LIBPATH:C:\projects\glutin\bin\x86_64-pc-windows-msvc" "ws2_32.lib" "userenv.lib" "advapi32.lib" "kernel32.lib" "shell32.lib" "msvcrt.lib" "compiler-rt.lib"
note:    Creating library C:\projects\glutin\target\debug\build\glutin-40bab6d10148d98f\build_script_build.lib and object C:\projects\glutin\target\debug\build\glutin-40bab6d10148d98f\build_script_build.exp

... (lots of warnings, see below) ...

build_script_build.o : error LNK2019: unresolved external symbol __imp__ZN7WGL_XML20h414720ad029f8e51qaaE referenced in function _ZN4main20hdd85b714c95cf787jaaE
build_script_build.o : error LNK2019: unresolved external symbol __imp__ZN7EGL_XML20h414720ad029f8e51kaaE referenced in function _ZN4main20hdd85b714c95cf787jaaE
build_script_build.o : error LNK2019: unresolved external symbol __imp__ZN7GLX_XML20h414720ad029f8e51waaE referenced in function _ZN4main20hdd85b714c95cf787jaaE
build_script_build.o : error LNK2019: unresolved external symbol __imp__ZN6GL_XML20h414720ad029f8e51eaaE referenced in function _ZN4main20hdd85b714c95cf787jaaE
C:\projects\glutin\target\debug\build\glutin-40bab6d10148d98f\build_script_build.exe : fatal error LNK1120: 4 unresolved externals

The four unresolved symbols refer to the four static variables exported by khronos_api.
This only happens with the 64bits version. The 32bits build works fine. EDIT: oops, 32bits was in fact using MinGW, so nevermind.

In addition to this, there are also a lot of warnings generated:

build_script_build.o : warning LNK4217: locally defined symbol _ZN8registry24RegistryBuilder$LT$R$GT$16consume_registry15__STATIC_FMTSTR20h5aefe2547183a934OQcE imported in function _ZN8registry24RegistryBuilder$LT$R$GT$16consume_registry20h7736587482988118975E
build_script_build.o : warning LNK4217: locally defined symbol _ZN8registry24RegistryBuilder$LT$R$GT$16consume_registry15__STATIC_FMTSTR20h5aefe2547183a9349LcE imported in function _ZN8registry24RegistryBuilder$LT$R$GT$16consume_registry20h7736587482988118975E
build_script_build.o : warning LNK4217: locally defined symbol _ZN8registry24RegistryBuilder$LT$R$GT$16consume_registry10_FILE_LINE20h61ca6051b049c413zMcE imported in function _ZN8registry24RegistryBuilder$LT$R$GT$16consume_registry20h7736587482988118975E
build_script_build.o : warning LNK4217: locally defined symbol _ZN20MAX_LOG_LEVEL_FILTER20h52e87f418f7a0ca4EaaE imported in function _ZN8registry24RegistryBuilder$LT$R$GT$16consume_registry20h7736587482988118975E
build_script_build.o : warning LNK4217: locally defined symbol _ZN8registry24RegistryBuilder$LT$R$GT$16consume_registry15__STATIC_FMTSTR20h5aefe2547183a934EOcE imported in function _ZN8registry24RegistryBuilder$LT$R$GT$16consume_registry20h7736587482988118975E
build_script_build.o : warning LNK4217: locally defined symbol _ZN8registry24RegistryBuilder$LT$R$GT$16consume_registry3LOC20h7853c3b976861309ENcE imported in function _ZN8registry24RegistryBuilder$LT$R$GT$16consume_registry20h7736587482988118975E
build_script_build.o : warning LNK4217: locally defined symbol _ZN8registry24RegistryBuilder$LT$R$GT$16consume_registry15__STATIC_FMTSTR20h5aefe2547183a934WPcE imported in function _ZN8registry24RegistryBuilder$LT$R$GT$16consume_registry20h7736587482988118975E
build_script_build.o : warning LNK4217: locally defined symbol _ZN8registry24RegistryBuilder$LT$R$GT$16consume_registry10_FILE_LINE20h61ca6051b049c413mQcE imported in function _ZN8registry24RegistryBuilder$LT$R$GT$16consume_registry20h7736587482988118975E

... (around 150 lines of similar warnings)

The symbols of these warnings refer to functions of the other build-dependency, which is gl_generator. I don't really know what they mean. Maybe they are shown only because of the linking errors and would be hidden otherwise?

Here is the complete log from appveyor for reference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    O-windowsOperating system: Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions