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 compile success from mac(M4) to windows static application #657

Open
cariers opened this issue Mar 21, 2025 · 0 comments
Open

cross compile success from mac(M4) to windows static application #657

cariers opened this issue Mar 21, 2025 · 0 comments

Comments

@cariers
Copy link

cariers commented Mar 21, 2025

This is a demo for cross compile mac to windows static program

tips: clone gflags, glog, opencv, opencv_contrib open source to disk.

1. build gflags

cmake .. \
  -DCMAKE_SYSTEM_NAME=Windows \
  -DCMAKE_SYSTEM_PROCESSOR=x86_64 \
  -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \
  -DGFLAGS_NAMESPACE=google \
  -DCMAKE_INSTALL_PREFIX=/Users/cariers.kim/x86/gflags

make -j$(sysctl -n hw.ncpu)
make install

2. build glog

cmake .. \
  -DCMAKE_SYSTEM_NAME=Windows \
  -DCMAKE_SYSTEM_PROCESSOR=x86_64 \
  -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \
  -Dgflags_DIR=/Users/cariers.kim/x86/gflags/lib/cmake/gflags \
  -DCMAKE_INSTALL_PREFIX=/Users/cariers.kim/x86/glog \
  -DWITH_UNWIND=none

make -j$(sysctl -n hw.ncpu)
make install

3. build opencv (I did build some module success )

cmake .. \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_SYSTEM_NAME=Windows \
  -DCMAKE_SYSTEM_PROCESSOR=x86_64 \
  -DCMAKE_CXX_FLAGS=-fpermissive \
  -DCMAKE_C_COMPILER=/opt/homebrew/bin/x86_64-w64-mingw32-gcc \
  -DCMAKE_CXX_COMPILER=/opt/homebrew/bin/x86_64-w64-mingw32-g++ \
  -DCMAKE_INSTALL_PREFIX=/Users/cariers.kim/x86/opencv \
  -DOPENCV_EXTRA_MODULES_PATH=/Users/cariers.kim/open-source/opencv_contrib-4.10.0/modules \
  -DGFLAGS_NAMESPACE=google \
  -DGFLAGS_INCLUDE_DIR=/Users/cariers.kim/x86/gflags/include/gflags \
  -DGflags_DIR=/Users/cariers.kim/x86/gflags/lib/cmake/gflags \
  -Dgflags_DIR=/Users/cariers.kim/x86/gflags/lib/cmake/gflags \
  -DGLOG_INCLUDE_DIR=/Users/cariers.kim/x86/glog/include/glog \
  -DGlog_DIR=/Users/cariers.kim/x86/glog/lib/cmake/glog \
  -DBUILD_SHARED_LIBS=OFF \
  -DBUILD_PROTOBUF=OFF \
  -DBUILD_opencv_hdf=OFF \
  -DBUILD_opencv_world=ON \
  -DBUILD_OPENEXR=ON \
  -DWITH_PROTOBUF=OFF \
  -DWITH_ZLIB_NG=ON 

make -j$(sysctl -n hw.ncpu)
make install

4. build opencv-rs applicaion

Cargo.toml

[package]
name = "rust-demo"
version = "0.1.0"
edition = "2024"


[dependencies]
opencv = { version = "0.94.2" , default-features = false, features = ["imgproc", "imgcodecs", "clang-runtime"] }

main.rs

use opencv::{Result, imgcodecs};

fn main() -> Result<()> {
    let image = imgcodecs::imread("lena.jpg", 0)?;
    // highgui::named_window("hello opencv!", 0)?;
    // highgui::imshow("hello opencv!", &image)?;
    // highgui::wait_key(10000)?;
    Ok(())
}

build shell

# link stdc++ static
export CXXSTDLIB=static=stdc++
# link opencv module static (static=static=module !important)
# because first "static=" is opencv find lib, second  "static=" is link to static  (has other method ?)
export OPENCV_LINK_LIBS=static=static=opencv_world4110,static=static=opencv_img_hash4110,static=static=IlmImf,static=static=ade,static=static=libjpeg-turbo,static=static=libopenjp2,static=static=libpng,static=static=libtiff,static=static=libwebp,static=static=z
# link path (both opencv and stdc++)
export OPENCV_LINK_PATHS="/Users/cariers.kim/x86/opencv/lib,/Users/cariers.kim/x86/opencv/lib/opencv4/3rdparty,/opt/homebrew/Cellar/mingw-w64/12.0.0_2/toolchain-x86_64/x86_64-w64-mingw32/lib"
# include opencv
export OPENCV_INCLUDE_PATHS="/Users/cariers.kim/x86/opencv/include/opencv4"

#build
cargo build --target x86_64-pc-windows-gnu --release -vv

Tks opencv-rs ! great !

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