我正在尝试从github存储库make
一个C++程序。我已经克隆了回购协议(protocol),并将其放入CD。按照说明,我运行make
进行构建。这是原始的Makefile:
# Makefile for heartbeat
appname := Heartbeat
CXX := g++
RM := rm -f
CXXFLAGS := -Wall -g -std=c++11 -I/usr/local/include/opencv4
LDFLAGS := -g
LDLIBS := -lopencv_core -lopencv_dnn -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_objdetect -lopencv_video -lopencv_videoio
SRCS := $(shell find . -name "*.cpp")
OBJS = $(subst .cpp,.o,$(SRCS))
all: $(appname)
$(appname): $(OBJS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(appname) $(OBJS) $(LDLIBS)
depend: .depend
.depend: $(SRCS)
$(RM) ./.depend
$(CXX) $(CXXFLAGS) -MM $^>>./.depend;
clean:
$(RM) $(appname) $(OBJS)
dist-clean: clean
$(RM) *~ .depend
include .depend
运行它时,出现以下错误:g++ -Wall -g -std=c++11 -I/usr/local/include/opencv4 -g -o Heartbeat ./RPPG.o ./Heartbeat.o ./opencv.o -lopencv_core -lopencv_dnn -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lobjdetect -lopencv_video -lopencv_videoio
ld: library not found for -lopencv_core
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Heartbeat] Error 1
所以我调整了-I include路径到opencv,以反射(reflect)我在计算机上安装的位置。我在这里安装了它(并在python中经常使用):Users/asi/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2
这样,我创建了一个新的Makefile:# Makefile for heartbeat
appname := Heartbeat
CXX := g++
RM := rm -f
CXXFLAGS := -Wall -g -std=c++11 -I/Users/asi/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include
LDFLAGS := -g
LDLIBS := -lopencv_core -lopencv_dnn -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lobjdetect -lopencv_video -lopencv_videoio
SRCS := $(shell find . -name "*.cpp")
OBJS = $(subst .cpp,.o,$(SRCS))
all: $(appname)
$(appname): $(OBJS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(appname) $(OBJS) $(LDLIBS)
depend: .depend
.depend: $(SRCS)
$(RM) ./.depend
$(CXX) $(CXXFLAGS) -MM $^>>./.depend;
clean:
$(RM) $(appname) $(OBJS)
dist-clean: clean
$(RM) *~ .depend
include .depend
但我仍然收到此错误:g++ -Wall -g -std=c++11 -I/Users/asi/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include -c -o Heartbeat.o Heartbeat.cpp
g++ -Wall -g -std=c++11 -I/Users/asi/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include -c -o opencv.o opencv.cpp
g++ -Wall -g -std=c++11 -I/Users/asi/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include -g -o Heartbeat ./RPPG.o ./Heartbeat.o ./opencv.o -lopencv_core -lopencv_dnn -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lobjdetect -lopencv_video -lopencv_videoio
ld: library not found for -lopencv_core
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Heartbeat] Error 1
我不确定该怎么办。我在-I调用引用的路径中安装了所有库。为什么make
找不到它们?作为引用,我在Mac(Catalina OS)上运行。
最佳答案
自制或多或少始终将其安装的所有二进制文件符号链接(symbolic link):
/usr/local/Cellar/PACKAGENAME/PACKAGEVERSION
至/usr/local/bin
因此您只需要在PATH上添加/usr/local/bin
即可获得所有自酿软件包的最新二进制文件。因此,让我们看一下我用自制安装的pdfimages
:ls -l /usr/local/bin/pdfimages
lrwxr-xr-x 1 mark admin 38 Jul 14 15:54 pdfimages -> ../Cellar/poppler/0.90.1/bin/pdfimages
同样,它将所有头文件放入
/usr/local/include
和中的所有库/usr/local/lib
因此您通常只需要编译以下内容:g++ -std=c++XX source.cpp -I /usr/local/include -L /usr/local/lib -lXXX -lYYY -lZZZ -o program
如果失败,只需使用
find
查找您的库,然后相应地设置-L XXX
:# Look for OpenCV libraries in /usr, /opt and $HOME
find /usr /opt $HOME -type f -iname "*opencv*so" 2> /dev/null
另外,您可以按照与here.所述完全相同的方式使用
pkgconfig
关于python - 在make调用期间make无法找到OpenCV库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63746424/