Reputation: 1679
I am trying to make
a C++ program from a github repo. I have cloned the repo and cd into it. Per instructions, I run make
to build. Here is the original 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
When I run it, I get this error:
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
So I adjusted the -I include path to opencv to reflect where I have it installed on my machine. I have it installed here (and use it frequently in python):
Users/asi/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2
With this, I made a new 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
but I still get this error:
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'm not sure what to do. I have all of the libraries installed in the path referenced by my -I call. Why can't make
find them?
For reference, I am running on a Mac (Catalina OS).
Upvotes: 1
Views: 362
Reputation: 207758
homebrew more or less always symlinks all binaries it installs from:
/usr/local/Cellar/PACKAGENAME/PACKAGEVERSION
to
/usr/local/bin
so you only need /usr/local/bin
on your PATH and you get the latest binaries of all homebrew packages. So,let's look at pdfimages
which I installed with homebrew:
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
Likewise, it puts all header files in
/usr/local/include
and all libraries in
/usr/local/lib
so you normally only need the following to compile:
g++ -std=c++XX source.cpp -I /usr/local/include -L /usr/local/lib -lXXX -lYYY -lZZZ -o program
Failing that, just look for your libraries with find
and then set -L XXX
accordingly:
# Look for OpenCV libraries in /usr, /opt and $HOME
find /usr /opt $HOME -type f -iname "*opencv*so" 2> /dev/null
Alternatively, you can use pkgconfig
in exactly the same way as described here.
Upvotes: 1