georust / proj

Rust bindings for the latest stable release of PROJ
https://docs.rs/proj
Apache License 2.0
137 stars 45 forks source link

Static compilation with musl not succeeded #66

Closed freedeaths closed 3 years ago

freedeaths commented 3 years ago

Question: Is it possible to compile the application statically with MUSL or other tools/methods? The application needs so many dependencies that it is not esay to deploy.

I have attemped:

  1. Compiled exmaple successful;
use proj::Proj;

extern crate geo_types;
use geo_types::Point;

fn main() {
    let from = "EPSG:2230";
    let to = "EPSG:26946";
    let ft_to_m = Proj::new_known_crs(&from, &to, None).unwrap();
    let result = ft_to_m
        .convert(Point::new(4760096.421921, 3744293.729449))
        .unwrap();
    println!("{}", result.x() as f64);
    println!("{}", result.y() as f64);
    //assert_approx_eq::assert_approx_eq!(result.x() as f64, 1450880.2910605003);
    //assert_approx_eq::assert_approx_eq!(result.y() as f64, 1141263.0111604529);
}
[package]
name = "testproj"
version = "0.1.0"
authors = ["freedeaths"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
proj = { version = "0.20.5", features = ["bundled_proj"] }
assert_approx_eq = "1.1"
geo-types = "0.6"

I could run this application in PC where I compiled in. BUT I can't send this binary to other pc which says "cannot find proj.db and balabala" after run this binary.

  1. Compiled this project as proj.rlib or proj.a successful(wrapped with libproj.a generated);

  2. Fail to compiled the application 1 with musl on Ubuntu Server 18.04 and got ERROR like:

undefined reference to `__dso_handle

undefined reference to `__cpu_indicator_init'

undefined reference to `__cpu_model'

sudo apt install musl-tools
rustup target add x86_64-unknown-linux-musl
CC=musl-gcc cargo build --release --target=x86_64-unknown-linux-musl
  1. Fail to compiled the application 1 with generated proj.a/proj.rlib in step 2, and got ERROR like
Package proj was not found in the pkg-config search path.
  Perhaps you should add the directory containing `proj.pc'
  to the PKG_CONFIG_PATH environment variable
  No package 'proj' found
  Package proj was not found in the pkg-config search path.
  Perhaps you should add the directory containing `proj.pc'
  to the PKG_CONFIG_PATH environment variable
  No package 'proj' found
freedeaths commented 3 years ago

Sorry, I got it.

Step 1:

Copy the application and proj.db to any pc;

Step 2:

export PROJ_LIB environment variable.

Done!

categulario commented 2 years ago

Hey @freedeaths ! Just ran into a similar problem. Where did you find the proj.db file? I'm trying to build a container for a project that depends on proj but I don't know where to copy the proj.db file from.