fairmath / openfhe-rs

OpenFHE-rs - a Rust interface for the OpenFHE library; documentation https://openfhe-rust-wrapper.readthedocs.io/
https://crates.io/crates/openfhe
BSD 2-Clause "Simplified" License
28 stars 6 forks source link

Error when building with "Custom crate installation from the source" #3

Open minnow54426 opened 4 months ago

minnow54426 commented 4 months ago

Hello, I got an error when running

cargo build

which say that

openfhe-rs/target/debug/build/openfhe-f060a627b59bf248/out/cxxbridge/crate/openfhe/src/SerialDeserial.h:3:10: fatal error: 'bits/stringfwd.h' file not found
warning: openfhe@0.1.5: #include "bits/stringfwd.h"
warning: openfhe@0.1.5:          ^~~~~~~~~~~~~~~~~~
warning: openfhe@0.1.5: 1 error generated.

error: failed to run custom build command for `openfhe v0.1.5 (/Users/lihao/code/rust/openfhe-rs)`

My cmake version is 3.29.0, clang version is 15.0.0 and cargo version is 1.78.0 in MacBook pro with M3.

minnow54426 commented 4 months ago

It seems that this file is distributed with GCC.

HovsepPapoyan commented 4 months ago

Thanks for the problem! I'm working on it.

HovsepPapoyan commented 4 months ago

I updated the master, please try building again.

minnow54426 commented 4 months ago

Sorry for late response. The new master can run cargo build successfully, great! There is still some issue with cargo test and cargo run with examples, the error is

Compiling openfhe v0.1.5 
error: linking with `cc` failed: exit status: 1

and the note is

note: ld: unknown options: -rpath=/usr/local/lib 
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

Thanks very much!

minnow54426 commented 4 months ago

Some further information. ChatGPT suggests to replace

println!("cargo::rustc-link-arg=-Wl,-rpath=/usr/local/lib");

with

println!("cargo::rustc-link-arg=-Wl,-rpath,/usr/local/lib");

which replace "=" with ",", then, after rebuild, test introduce a new error

ld: warning: object file (/Users/openfhe-rs/target/debug/build/openfhe-012c5e72e626bb2b/out/libopenfhe.a[2](3a03b8d1686208bd-lib.rs.o)) was built for newer 'macOS' version (14.4) than being linked (14.0)

Then I add a new line to build.rs

println!("cargo::rustc-env=MACOSX_DEPLOYMENT_TARGET=14.4");

Finally the error with test becomes

ld: warning: search path './openfhe-development/install/lib' not found
          Undefined symbols for architecture arm64:
            "lbcrypto::PseudoRandomNumberGenerator::m_prng", referenced from:
                lbcrypto::PseudoRandomNumberGenerator::GetPRNG() in libopenfhe.a[5](2e40c9e35e9506f4-CryptoContext.o)
                lbcrypto::PseudoRandomNumberGenerator::GetPRNG() in libopenfhe.a[5](2e40c9e35e9506f4-CryptoContext.o)
          ld: symbol(s) not found for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

I go to C++ version of openFHE and checked, m_prng does exist and is defined in namespace lbcrypto as follows

std::shared_ptr<PRNG> PseudoRandomNumberGenerator::m_prng = nullptr;

I have been used C++ version of openFHE via cmake for a long time, and nothing is wrong with this m_prng.

navasvarela commented 6 days ago

I am experiencing the same error about "Undefined symbols" reported above with the current version in main. Any ideas/workarounds?