mudler / LocalAI

:robot: The free, Open Source OpenAI alternative. Self-hosted, community-driven and local-first. Drop-in replacement for OpenAI running on consumer-grade hardware. No GPU required. Runs gguf, transformers, diffusers and many more models architectures. It allows to generate Text, Audio, Video, Images. Also with voice cloning capabilities.
https://localai.io
MIT License
21.77k stars 1.66k forks source link

Mac OS 13.4 M2 Pro with latest code build error 'opencv2/opencv.hpp' file not found #701

Open luoweb opened 1 year ago

luoweb commented 1 year ago

LocalAI version: git commit: commit 0780be022cb709d531acb055ac8a858f032d3e19 (HEAD -> master, origin/master, origin/HEAD)

Environment, CPU architecture, OS, and Version: Mac OS 13.4 M2 Pro

Describe the bug compile error with BUILD_TYPE=metal build GO_TAGS=stablediffusion,tts

(base) block@192 LocalAI % make BUILD_TYPE=metal build
(base) block@192 LocalAI % export GO_TAGS=stablediffusion,tts

cp -rf overrides/* stable-diffusion/x86/vs2019_opencv-mobile_ncnn-dll_demo/vs2019_opencv-mobile_ncnn-dll_demo/
c++ -I./ncnn -I./ncnn/src -I./ncnn/build/src/ -I. -I./stable-diffusion/x86/vs2019_opencv-mobile_ncnn-dll_demo/vs2019_opencv-mobile_ncnn-dll_demo  -O3 -DNDEBUG -std=c++17 -fPIC -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function stablediffusion.cpp -o stablediffusion.o -c 
In file included from stablediffusion.cpp:9:
In file included from ./ncnn/src/net.h:18:
In file included from ./ncnn/src/blob.h:18:
./ncnn/src/mat.h:1164:9: warning: '_Atomic' is a C11 extension [-Wc11-extensions]
        NCNN_XADD(m.refcount, 1);
        ^
./ncnn/src/allocator.h:125:56: note: expanded from macro 'NCNN_XADD'
#define NCNN_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL)
                                                       ^
In file included from stablediffusion.cpp:9:
In file included from ./ncnn/src/net.h:18:
In file included from ./ncnn/src/blob.h:18:
./ncnn/src/mat.h:1188:9: warning: '_Atomic' is a C11 extension [-Wc11-extensions]
        NCNN_XADD(refcount, 1);
        ^
./ncnn/src/allocator.h:125:56: note: expanded from macro 'NCNN_XADD'
#define NCNN_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL)
                                                       ^
In file included from stablediffusion.cpp:9:
In file included from ./ncnn/src/net.h:18:
In file included from ./ncnn/src/blob.h:18:
./ncnn/src/mat.h:1193:21: warning: '_Atomic' is a C11 extension [-Wc11-extensions]
    if (refcount && NCNN_XADD(refcount, -1) == 1)
                    ^
./ncnn/src/allocator.h:125:56: note: expanded from macro 'NCNN_XADD'
#define NCNN_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL)
                                                       ^
In file included from stablediffusion.cpp:11:
./stable-diffusion/x86/vs2019_opencv-mobile_ncnn-dll_demo/vs2019_opencv-mobile_ncnn-dll_demo/decoder_slover.h:11:10: fatal error: 'opencv2/opencv.hpp' file not found
#include <opencv2/opencv.hpp>
         ^~~~~~~~~~~~~~~~~~~~
3 warnings and 1 error generated.
make[1]: *** [stablediffusion.o] Error 1
make: *** [go-stable-diffusion/libstablediffusion.a] Error 2

To Reproduce make BUILD_TYPE=metal build

Expected behavior build local-ai

Logs as bug describes

Additional context v1.19.2 compile normal

mudler commented 1 year ago

you seem to miss opencv2 header files. you can either drop stablediffusion from your GO_TAGS or install opencv2.

luoweb commented 1 year ago

unset GO_TAGS; exec " make build" still compile error:

d531acb055ac8a858f032d3e19"" -tags "" -o local-ai ./
# github.com/go-skynet/LocalAI/pkg/whisper
pkg/whisper/whisper.go:76:34: not enough arguments in call to context.Process
        have ([]float32, nil)
        want ([]float32, "github.com/ggerganov/whisper.cpp/bindings/go/pkg/whisper".SegmentCallback, "github.com/ggerganov/whisper.cpp/bindings/go/pkg/whisper".ProgressCallback)
# github.com/go-skynet/go-bert.cpp
In file included from gobert.cpp:6:
go-bert/bert.cpp/bert.cpp:693:74: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]
# github.com/go-skynet/go-llama.cpp
binding.cpp:634:15: warning: 'llama_init_from_file' is deprecated: please use llama_load_model_from_file combined with llama_new_context_with_model instead [-Wdeprecated-declarations]
go-llama/llama.cpp/llama.h:162:15: note: 'llama_init_from_file' has been explicitly marked deprecated here
go-llama/llama.cpp/llama.h:30:56: note: expanded from macro 'DEPRECATED'
# github.com/go-skynet/go-ggml-transformers.cpp
replit.cpp:65:50: warning: format specifies type 'int' but the argument has type 'std::vector<unsigned long>::value_type' (aka 'unsigned long') [-Wformat]
make: *** [build] Error 1
mudler commented 1 year ago

seems you are using master, that was just fixed in https://github.com/go-skynet/LocalAI/pull/702.

run git pull again

luoweb commented 1 year ago

you seem to miss opencv2 header files. you can either drop stablediffusion from your GO_TAGS or install opencv2. opencv@2 has been disabled

(base) block@192 LocalAI % brew install opencv@2
Warning: No remote 'origin' in /opt/homebrew/Library/Taps/homebrew/homebrew-services, skipping update! Running brew update --auto-update... Error: opencv@2 has been disabled because it is not supported upstream!

luoweb commented 1 year ago

seems you are using master, that was just fixed in #702.

run git pull again

it's OK now without GO_TAGS

Ephex2 commented 1 year ago

I had the same issue and resolved it by:

  1. Installing OpenCV following the instructions here
  2. Navigate into the go-stable-diffusion directory and create a soft link to the opencv2 folder, ex:
    cd go-stable-diffusion
    ln -s /usr/include/opencv4/opencv2 opencv2

It may be worth noting that I did this on a linux box and not on MacOS, though it seemed to solve the same problem.

localai-bot commented 11 months ago

:warning::warning::warning::warning::warning:

Hi! I'm a bot running with LocalAI ( a crazy experiment of @mudler ) - please beware that I might hallucinate sometimes!

_but.... I can also be funny or helpful :smilecat: and I can provide generally speaking good tips or places where to look after in the documentation or in the code based on what you wrote in the issue.

Don't engage in conversation with me, I don't support (yet) replying!

:warning::warning::warning::warning::warning:

The issue seems to be related to the use of C++11 atomic operations in the NCNN library, which are not supported on macOS Mojave (released in 2018) and earlier. The error message suggests that the code is compiled with -std=c++17 flag, which may also be causing issues with the older version of OpenCV used by the LocalAI project. To fix this issue, you can try the following:

Sources:

wysstartgo commented 11 months ago

I got the same error