rust-pcap / pcap

Rust language pcap library
Apache License 2.0
620 stars 142 forks source link

Can it build on Linux to windows #246

Open TomatoMr opened 2 years ago

TomatoMr commented 2 years ago

I want to build on Linux to Windows, can it supports?

Wojtek242 commented 2 years ago

Yes, please see the README for instructions

Wojtek242 commented 2 years ago

Oh sorry, misunderstood your question. I thought you asked if it builds on Windows.

Building from Linux to Windows should work since we support Windows builds, but we don't have it documented.

TomatoMr commented 2 years ago

😁Thank you very much for your reply. I would be very grateful if there are documents or construction guidelines.

TomatoMr commented 2 years ago

I used the build tool: cargo-xwin , and tried to run:

cargo xwin build --target x86_64-pc-windows-msvc

then, I got the failed info:

  = note: lld-link: error: could not open 'wpcap.lib': No such file or directory
          lld-link: error: could not open 'pcap.lib': No such file or directory

image

I have downloaded the SDK of WinPcap and copied wpcap.lib and packet.lib in the x64 directory to Linux. But I can't find pcap.lib

Wojtek242 commented 2 years ago

I'm no expert on cross-compiling so I can't help you here. However, I'll reopen the issue so that somebody else perhaps will see this and answer.

TomatoMr commented 2 years ago

tks🌹

Stargateur commented 2 years ago

have you try use LIB env variable to pin point the location of wpcap.lib ? also try to just put the file at the root of the project. Should work.

TomatoMr commented 2 years ago

have you try use LIB env variable to pin point the location of wpcap.lib ? also try to just put the file at the root of the project. Should work.

Yes, I tried it, it didn't work. I also tried to copy and rename wpcap.lib to pcap.lib, but it still failed with the error: lld-link: error: could not open 'pcap.lib': No such file or directory. I can't find pcap.lib.

robs-zeynet commented 1 year ago

You might try building with a build.rs (which puts the build information into the build process) instead of the manual environmental variable. The following build.rs works for me on a "built for windows, on windows" build which I haven't tried from Linux, but should be a reasonable starting point. It assumes the same directory structure as what comes out of the npcap dev libs, e.g., that if you want a x64 bit build, you want to use the "lib/x64" subdir.

robsh@LAPTOP-O7RS71IJ MINGW64 ~/git/myproj (main)
$ find lib/
lib/
lib/x64
lib/x64/Packet.lib
lib/x64/wpcap.lib

robsh@LAPTOP-O7RS71IJ MINGW64 ~/git/myproj (main)
$ ls build.rs
build.rs

$ cat build.rs
use std::env;
use std::path::Path;

fn main() {
    let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
    println!(
        "cargo:rustc-link-search=native={}",
        Path::new(&dir).join("lib/x64").display()
    );
}
TomatoMr commented 1 year ago

You might try building with a build.rs (which puts the build information into the build process) instead of the manual environmental variable. The following build.rs works for me on a "built for windows, on windows" build which I haven't tried from Linux, but should be a reasonable starting point. It assumes the same directory structure as what comes out of the npcap dev libs, e.g., that if you want a x64 bit build, you want to use the "lib/x64" subdir.

robsh@LAPTOP-O7RS71IJ MINGW64 ~/git/myproj (main)
$ find lib/
lib/
lib/x64
lib/x64/Packet.lib
lib/x64/wpcap.lib

robsh@LAPTOP-O7RS71IJ MINGW64 ~/git/myproj (main)
$ ls build.rs
build.rs

$ cat build.rs
use std::env;
use std::path::Path;

fn main() {
    let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
    println!(
        "cargo:rustc-link-search=native={}",
        Path::new(&dir).join("lib/x64").display()
    );
}

@robs-zeynet thank you, i had tried it, but it not worked