microsoft / onnxruntime-genai

Generative AI extensions for onnxruntime

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can this library be build without having to link OpenCV?

janeisklar opened this issue · comments

I believe that #478 added a dependency to OpenCV through ortextensions. Is there any way to build this without depending on OpenCV?

Undefined symbols for architecture x86_64:
  "cv::copyMakeBorder(cv::_InputArray const&, cv::_OutputArray const&, int, int, int, int, int, cv::Scalar_<double> const&)", referenced from:
      padding_336(cv::Mat const&) in xxx.rlib[211](image_processor.cc.o)
  "cv::Mat::Mat(std::__1::vector<int, std::__1::allocator<int>> const&, int, void*, unsigned long const*)", referenced from:
      image_decoder(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<unsigned char>&) in xxx.rlib[211](image_processor.cc.o)
      phi3_hd_transform(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<float>&, Ort::Custom::Tensor<long long>&, Ort::Custom::Tensor<long long>&) in xxx.rlib[211](image_processor.cc.o)
  "cv::Mat::Mat(int, int, int, void*, unsigned long)", referenced from:
      phi3_hd_transform(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<float>&, Ort::Custom::Tensor<long long>&, Ort::Custom::Tensor<long long>&) in xxx.rlib[211](image_processor.cc.o)
  "cv::Mat::Mat()", referenced from:
      phi3_hd_transform(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<float>&, Ort::Custom::Tensor<long long>&, Ort::Custom::Tensor<long long>&) in xxx.rlib[211](image_processor.cc.o)
      hd_transform(cv::Mat const&, int) in xxx.rlib[211](image_processor.cc.o)
      padding_336(cv::Mat const&) in xxx.rlib[211](image_processor.cc.o)
  "cv::Mat::~Mat()", referenced from:
      image_decoder(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<unsigned char>&) in xxx.rlib[211](image_processor.cc.o)
      image_decoder(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<unsigned char>&) in xxx.rlib[211](image_processor.cc.o)
      image_decoder(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<unsigned char>&) in xxx.rlib[211](image_processor.cc.o)
      image_decoder(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<unsigned char>&) in xxx.rlib[211](image_processor.cc.o)
      phi3_hd_transform(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<float>&, Ort::Custom::Tensor<long long>&, Ort::Custom::Tensor<long long>&) in xxx.rlib[211](image_processor.cc.o)
      phi3_hd_transform(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<float>&, Ort::Custom::Tensor<long long>&, Ort::Custom::Tensor<long long>&) in xxx.rlib[211](image_processor.cc.o)
      phi3_hd_transform(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<float>&, Ort::Custom::Tensor<long long>&, Ort::Custom::Tensor<long long>&) in xxx.rlib[211](image_processor.cc.o)
      phi3_hd_transform(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<float>&, Ort::Custom::Tensor<long long>&, Ort::Custom::Tensor<long long>&) in xxx.rlib[211](image_processor.cc.o)
      phi3_hd_transform(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<float>&, Ort::Custom::Tensor<long long>&, Ort::Custom::Tensor<long long>&) in xxx.rlib[211](image_processor.cc.o)
      phi3_hd_transform(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<float>&, Ort::Custom::Tensor<long long>&, Ort::Custom::Tensor<long long>&) in xxx.rlib[211](image_processor.cc.o)
      phi3_hd_transform(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<float>&, Ort::Custom::Tensor<long long>&, Ort::Custom::Tensor<long long>&) in xxx.rlib[211](image_processor.cc.o)
      phi3_hd_transform(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<float>&, Ort::Custom::Tensor<long long>&, Ort::Custom::Tensor<long long>&) in xxx.rlib[211](image_processor.cc.o)
      ...
  "cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)", referenced from:
      phi3_hd_transform(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<float>&, Ort::Custom::Tensor<long long>&, Ort::Custom::Tensor<long long>&) in xxx.rlib[211](image_processor.cc.o)
      hd_transform(cv::Mat const&, int) in xxx.rlib[211](image_processor.cc.o)
  "cv::imdecode(cv::_InputArray const&, int)", referenced from:
      image_decoder(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<unsigned char>&) in xxx.rlib[211](image_processor.cc.o)
  "cv::Mat::total() const", referenced from:
      image_decoder(Ort::Custom::Tensor<unsigned char> const&, Ort::Custom::Tensor<unsigned char>&) in xxx.rlib[211](image_processor.cc.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Would you please share a little more on your request? Is OpenCV not buildable for your machine/platform?

Could you share your build command? You shouldn't be seeing this error since we pull and build OpenCV from scratch.

Does your application depend on OpenCV outside of onnxruntime-genai/onnxruntime-extensions?

My apologies, this ticket is indeed lacking quite some context:)

I'm building a static library of onnxruntime-genai while specifying a static build of onnxruntime like so:
python3 build.py --ort_home ../onnxruntime-build/output/static_lib --parallel --config Release --skip_wheel --skip_csharp
(I also had to disable the shared library target in the CMakeList.txt as I only supply a static build of onnxruntime)

When I then use the libonnxruntime-genai-static.a in my application, while building I am facing the linking error that I copied. (It's a rust application, but I don't think that's important here).

I can work around this by adding the following static libraries: liblibjpeg-turbo.a, libopencv_core.a, libopencv_imgproc.a, libopencv_imgcodecs.a, liblibpng.a, libz.a.

However, I don't need any of those libraries in my application, neither do I need image models, so I was wondering if I could somehow build a static version of your library that does not depend on OpenCV, as that would reduce the number of dependencies quite a bit for me.

Thank you for the context. We do not have plans as of now to add conditional building for different type of models. We only generate an all-in-one package right now.

I have not tried building an example against the ort-genai static lib, but I would assume that we do not need to link against these libs since the ort-genai static lib already has linked against these static libs since we link with ort extensions. Our python cmake file links against the static lib but does not need to link against the other libs you mentioned. And it builds fine. So, I am not sure where the linker error comes from.