Search code examples
macosrustgmp

Rust compile error on macOS related to GMP


Something like

use super::gmp::mpz::Mpz;
...
pub type MyMPZ = Mpz;

...

fn a() -> Option<MyMPZ>;

It (along with many other Rust files, libs and other dependencies) compiles and runs OK on Ubuntu and even Windows, but on macOS Mojave I get

expected struct `gmp::mpz::Mpz`, found enum `std::option::Option`

note: expected type `&gmp::mpz::Mpz`
                                                      found type `&std::option::Option`

I installed GMP with Brew, but I tried with GMP 6.1.2 built by myself with the same results.

Update 1: Seems MCVE doesn't make much sense since I have two exact copies of project in same root like root\example1 and root\example2. One copy builds ok, another gives the error message. Tried cargo clean etc numerous times to same effect.

Update 2: Seems it's definitely some sort of caching issue. Because when I build dependencies, they take custom built 32bit version of gmp.lib from C:\Users\<userName>\.rustup\toolchains\nightly-i686-pc-windows-msvc\lib\rustlib\i686-pc-windows-msvc\lib. So if I checkout dependency and build it separately - tests run there. If I build the whole project, and using my own build dependency crates as .lib I at some point was getting

expected struct `gmp::mpz::Mpz`, found another struct `gmp::mpz::Mpz`

that seems like mixing of GMP 32/64 bit libraries to me.


Solution

  • Ok so it was cargo dependency hell:) - after multiple unsuccessful reinstalls, cleaning etc I finally was able to rebuild by manually downloading and rebuilding and re-referencing local paths of dependencies that were referenced with git. From then on - all was building fine no matter if I referenced locally or via git or crates.