Skip to content

Generate standalone libs so that projects can link without the Windows SDK #142

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

Closed
Boddlnagg opened this issue May 16, 2020 · 12 comments
Closed
Labels
enhancement New feature or request

Comments

@Boddlnagg
Copy link

In a prototype, I migrated from winrt-rust to winrt-rs in my MIDI library midir, see Boddlnagg/midir#56.

In the CI for that project, I also test building with the windows-gnu toolchain, and apparently it doesn't work with winrt-rs. I'm getting a linker error:

error: linking with `i686-w64-mingw32-gcc` failed: exit code: 1
  |
  = note: "i686-w64-mingw32-gcc" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-Wl,--large-address-aware" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\crt2.o" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\rsbegin.o" "-L" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.178gp5vv20m57swx.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.17lqo5gaw6vbpgvd.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.18bbq33bsjqkmi22.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.1h35mts5zdb7dspg.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.1h9u4ot3xckd33qs.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.1o1av9at7wet31bv.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.1r1zb1hc9v0oq0tp.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.1u7jitfxdw3jfgap.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.1uq02ga3avw5bj73.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.1uxwgv9lny6edhlc.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.1vix29wqqy997fjw.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.21mafq2uumgdjehv.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.21w5c3u2wtlgfiwq.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.270t5ey7193k7xxk.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.29l55o8s492q4qnb.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.29qtaphadllj0lgd.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.2aokq0d3ju5suxb2.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.2bbn825gtd53pwi1.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.2djlwiar9rh5ei4a.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.2dokhz5azweb3z6n.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.2eawyd7m64iqrjwu.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.2enw982yw7lthfez.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.2hrqxtnf0m5dmtpa.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.2jnrhas7zg1iisbd.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.2n6bwjn58o7x5zi7.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.2za4vdj8iu7ljzl2.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.36tuhlc5sspdebep.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.371zpbswlzqqugxm.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.3hcu3ipjb2wwdfb1.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.3t01tzuwloqvzz7m.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.3wh8dlo6faggud5w.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.440zbndm6qxljc6b.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.45eni2xrvra92ghb.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.47c82fenc3oyn4zq.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.498y9nru3bliwp6r.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.4fpwe8vlwtdgyshy.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.4lfyx6g2i7380t96.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.4m2lympeawq8j42q.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.4m32gle9cevzwojv.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.4omt98q1wokpzi7.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.4ttjsb5of4hc058m.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.56h0jnutigp2bc6a.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.5ceeh4k8i945be7w.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.5cj344q3oy347f50.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.5cnjrvj6id44idaf.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.60hhllpsfol0bi9.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.ns6d6t3e5cxt7q2.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.rwae5zwc3shkvmh.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.wd4pu6uusa0saa7.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.wj9ofnamozf46f0.rcgu.o" "-o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.exe" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-2cb3d4fa0b8bc5c0.1emjpbadwe256i0s.rcgu.o" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "D:\\a\\1\\s\\target\\debug\\deps" "-L" "C:\\Users\\VssAdministrator\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\winapi-i686-pc-windows-gnu-0.4.0\\lib" "-L" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib" "-Wl,-Bstatic" "D:\\a\\1\\s\\target\\debug\\deps\\libmidir-5846db035084a76c.rlib" "D:\\a\\1\\s\\target\\debug\\deps\\libwinrt-43c07baecdee4529.rlib" "D:\\a\\1\\s\\target\\debug\\deps\\libsha1-1251e7be80ac93cd.rlib" "D:\\a\\1\\s\\target\\debug\\deps\\libmemalloc-edf20606f7aab321.rlib" "-Wl,--start-group" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libstd-bd1b8695fe14e411.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libpanic_unwind-f5df88057745cf1d.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libhashbrown-b032eaab07efddbb.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\librustc_std_workspace_alloc-2d7265cf9e3a6fe1.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libbacktrace-57721ece4aa20e6a.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libbacktrace_sys-9b62612959cb7cdc.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\librustc_demangle-bd8fdd40f76804fd.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libunwind-6840040bfdf00f27.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libcfg_if-ba28ff170a75e142.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\liblibc-d645c440bd72b41b.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\liballoc-6b2a5dbd177e6684.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\librustc_std_workspace_core-ba2b6b2c16212cce.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libcore-4723b0041a858cf9.rlib" "-Wl,--end-group" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libcompiler_builtins-088cd71181439166.rlib" "-Wl,-Bdynamic" "-lkernel32" "-lonecore" "-ladvapi32" "-lws2_32" "-luserenv" "-Wl,-Bstatic" "-lgcc_eh" "-lpthread" "-Wl,-Bdynamic" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmsvcrt" "-luser32" "-lkernel32" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\rsend.o"
  = note: ld: cannot find -lonecore

The requirement to link with onecore seems to come from https://github.com/microsoft/winrt-rs/blob/ed46a71f506c343b3eb4fa6c15a4d9db1397ebcf/src/runtime.rs#L15-L24.

@Boddlnagg
Copy link
Author

The same thing worked with winrt-rust, where CoIncrementMTAUsage and RoGetActivationFactory is pulled in via winapi-rs.

@kennykerr
Copy link
Collaborator

Thanks Patrick, I'll probably do something similar and have winrt-rs generate its own lib for the handful of PAL functions that it needs.

@kennykerr kennykerr changed the title Linker error when building with the windows-gnu toolchain Generate standalone libs so that projects can link without the Windows SDK May 16, 2020
@kennykerr kennykerr added the enhancement New feature or request label May 16, 2020
@Alovchin91
Copy link
Contributor

Alovchin91 commented May 29, 2020

@kennykerr Here's a pretty simple example of how you can generate include libs in the build script:

https://github.com/Alovchin91/winrt-rs/commit/8cda7baa8f7c5c8e56eac20e31720062b5b8a518

build.rs:

use std::env;
use std::process::Command;

fn main() {
    if env::var("CARGO_CFG_WINDOWS").is_err() {
        panic!("Only Windows operating system is supported.")
    }

    if "gnu" == &env::var("CARGO_CFG_TARGET_ENV").unwrap().to_lowercase() {
        gen_coremessaging_lib();
    }
}

fn gen_coremessaging_lib() {
    let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
    let lib_path = std::path::Path::new(&manifest_dir).join("lib");

    let out_dir = env::var("OUT_DIR").unwrap();
    let out_path = std::path::Path::new(&out_dir);

    // build libcoremessaging.a
    let status = Command::new("dlltool")
        .arg("-d")
        .arg(lib_path.join("CoreMessaging.def"))
        .arg("-l")
        .arg(out_path.join("libcoremessaging.a"))
        .status()
        .unwrap();

    if !status.success() {
        panic!("Failed to generate libcoremessaging.a")
    }

    println!("cargo:rustc-link-search=native={}", out_dir);
}

CoreMessaging.def:

LIBRARY "CoreMessaging.dll"
EXPORTS
CreateDispatcherQueueController

This sample is for GNU toolchain (so MinGW can compile and run the tests), but I think for MSVC the idea is largely the same with the only difference being the use of LIB.exe iso dlltool.

I'm not so sure if it's worth a PR to fix the tests for GNU toolchain (since you need a LoadLibrary impl anyway) though.

@kennykerr
Copy link
Collaborator

Thanks, I experimented with something like this here a while back, but it looks like it would require different code for each toolchain.

@Alovchin91
Copy link
Contributor

Do you plan to support anything except Windows? If not, you should be good to go with 2 tools - LIB.exe for MSVC and dlltool for GNU. It should also work for cross-compiling: here's dlltool on my Mac for example:

➜ x86_64-w64-mingw32-dlltool -V
GNU x86_64-w64-mingw32-dlltool (GNU Binutils) 2.34
Copyright (C) 2020 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.

It's part of mingw-w64 Homebrew package of course.

@Boddlnagg
Copy link
Author

The supposed fix in #166 didn't help: I'm still getting a linker error:

error: linking with `i686-w64-mingw32-gcc` failed: exit code: 1
  |
  = note: "i686-w64-mingw32-gcc" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-Wl,--large-address-aware" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\crt2.o" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\rsbegin.o" "-L" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.12w33p08z9m24bcn.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.16atz8xj0jwzh1vo.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.18baoqy8fjianaar.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.1cysc10xuoifavxw.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.1hyj3xuug3jt5uwf.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.1plr7ggonn22x3ov.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.1vesdbe5skmvr0vm.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.201v0z8600pekuiy.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.24snq9lrog9pdd0j.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.29ljrdv3vo7p9i71.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.2lshssd3n5b6lwit.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.2m85uhk846cz6hc1.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.2mbm7vdvbrta3hxl.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.2sx79ump7w2t1ipr.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.2vzc59unqdtr47zf.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.34x6z5tpjo6wgyzh.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.36j5uw22skly0kaz.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.38iegwv16gi5xz55.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.3mq1ehimklz4hqe2.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.3p4d3hu68j7hl0qt.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.3rq8a9dzrbyiumaf.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.3umsfegjv7a44gmu.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.3v3zbtxh0zkftdwn.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.3vax36hlzmo63aw6.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.438w4jsfdpfmcg88.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.4527gr4vuuhpzt93.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.475qec19e7u4vomu.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.4i16kg5she6kgx35.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.4ziwzvcjyil394y9.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.50lon9f2wd7en6ch.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.53el01pp0qcshhet.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.54zsctcnw71l388o.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.57d2fy8gvo2zxgny.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.5bennbfbs6ei0c6.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.5bthfo7e9kqfd3ei.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.fawtbqded1stu5z.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.g2d0l3bzu4f4d6.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.gye5d4fsdus0jq1.rcgu.o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.ks5h6dfaqgzoh8u.rcgu.o" "-o" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.exe" "D:\\a\\1\\s\\target\\debug\\examples\\test_list_ports-b6af4d00610949b9.3b06aj67eowys031.rcgu.o" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "D:\\a\\1\\s\\target\\debug\\deps" "-L" "C:\\Users\\VssAdministrator\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\winapi-i686-pc-windows-gnu-0.4.0\\lib" "-L" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib" "-Wl,-Bstatic" "D:\\a\\1\\s\\target\\debug\\deps\\libmidir-35b8ed0932dadbf3.rlib" "D:\\a\\1\\s\\target\\debug\\deps\\libwinrt-77de8ef366ed6997.rlib" "D:\\a\\1\\s\\target\\debug\\deps\\libwinrt_build-7aef695a3b7ba757.rlib" "D:\\a\\1\\s\\target\\debug\\deps\\libwinmd-0900ccbc6db085e4.rlib" "D:\\a\\1\\s\\target\\debug\\deps\\libserde_json-e8151178171c4673.rlib" "D:\\a\\1\\s\\target\\debug\\deps\\libryu-41bf66a2e6632f28.rlib" "D:\\a\\1\\s\\target\\debug\\deps\\libitoa-7918d636d21c90b1.rlib" "D:\\a\\1\\s\\target\\debug\\deps\\libserde-06b6baf3a060047f.rlib" "D:\\a\\1\\s\\target\\debug\\deps\\libsha1-1251e7be80ac93cd.rlib" "D:\\a\\1\\s\\target\\debug\\deps\\libquote-19be48fb7db4ce87.rlib" "D:\\a\\1\\s\\target\\debug\\deps\\libproc_macro2-69b6c99bd57dd654.rlib" "D:\\a\\1\\s\\target\\debug\\deps\\libunicode_xid-1d6169287cd8448e.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libproc_macro-eff6ab6b84fbad61.rlib" "D:\\a\\1\\s\\target\\debug\\deps\\libmemalloc-edf20606f7aab321.rlib" "-Wl,--start-group" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libstd-bd1b8695fe14e411.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libpanic_unwind-f5df88057745cf1d.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libhashbrown-b032eaab07efddbb.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\librustc_std_workspace_alloc-2d7265cf9e3a6fe1.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libbacktrace-57721ece4aa20e6a.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libbacktrace_sys-9b62612959cb7cdc.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\librustc_demangle-bd8fdd40f76804fd.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libunwind-6840040bfdf00f27.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libcfg_if-ba28ff170a75e142.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\liblibc-d645c440bd72b41b.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\liballoc-6b2a5dbd177e6684.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\librustc_std_workspace_core-ba2b6b2c16212cce.rlib" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libcore-4723b0041a858cf9.rlib" "-Wl,--end-group" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\libcompiler_builtins-088cd71181439166.rlib" "-Wl,-Bdynamic" "-lkernel32" "-lwindowsapp" "-loleaut32" "-ladvapi32" "-lws2_32" "-luserenv" "-Wl,-Bstatic" "-lgcc_eh" "-lpthread" "-Wl,-Bdynamic" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmsvcrt" "-luser32" "-lkernel32" "C:\\Rust\\.rustup\\toolchains\\stable-i686-pc-windows-gnu\\lib\\rustlib\\i686-pc-windows-gnu\\lib\\rsend.o"
  = note: ld: cannot find -lwindowsapp

(now -lwindowsapp instead of -lonecore)

See https://dev.azure.com/Boddlnagg/midir/_build/results?buildId=97&view=logs&j=74eee6b2-7363-50eb-44ff-40f28c207e0f&t=5683acc6-877f-5740-1fa6-02d56753eadc

@kennykerr
Copy link
Collaborator

Thanks @Boddlnagg - since I have no control over what libs you have on your build machine, this issue is still open and I'm still planning to solve the original issue which is to "Generate standalone libs so that projects can link without the Windows SDK". Until I get around to that, I believe the MSVC targets should work.

@Boddlnagg
Copy link
Author

Yes, the MSVC targets work, and it's not super urgent. I just happened to have set up CI testing for 32-bit GNU windows target in my project (because I wanted as much platform coverage as possible for my crossplatform library), otherwise I wouldn't even have noticed this.

@retep998
Copy link

An alternative is to finally get raw-dylib implemented. That would allow linking to system libraries on Windows without needing the libraries nor having to generate import libraries with lib.exe/dlltool.

@kennykerr
Copy link
Collaborator

I'd love it if we could leverage raw-dylib but that seems like its still months away from being usable and I don't know anyone with the necessary compiler skills to help out. 😢

@kennykerr
Copy link
Collaborator

I think for now what I'll have to do is generate a tool that will build a .lib file from metadata. This requires calling both cl.exe (or equivalent) to produce an .obj for calling convention and then calling lib.exe (or equivalent) to produce the .lib for all of the externs. Not as elegant or convenient as raw-dylib though, but we can at least save the .lib and only rebuild on demand.

@kennykerr
Copy link
Collaborator

I have pinned the following issue describing the problem as it is a common question: #463

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants