Reputation: 820
I have a project, which uses opencv library. Today I have upgraded my Mac OS X Lion to Mavericks and now I am wondering why it does not compile anymore because of the following error:
c++ -O2 -g -Wall -fmessage-length=0 -c -o Hello.o Hello.cpp
Hello.cpp:2:10: fatal error: 'opencv/cv.h' file not found
#include "opencv/cv.h"
^
1 error generated.
make: *** [Hello.o] Error 1
Here's the code of Hello.cpp:
#include <iostream>
#include "opencv/cv.h"
using namespace std;
int main(){
return 0;
}
Here's my makefile:
CXXFLAGS = -O2 -g -Wall -fmessage-length=0
OBJS = Hello.o
LIBS = -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_gpu
INCPATH = -I/usr/local/Cellar/opencv/2.4.6.1/include
LIBPATH = -L/usr/local/Cellar/opencv/2.4.6.1/lib
TARGET = Hello
$(TARGET): $(OBJS)
g++ $(INCPATH) $(LIBPATH) -o $(TARGET) $(OBJS) $(LIBS)
all: $(TARGET)
clean:
rm -f $(OBJS) $(TARGET)
I have to say that I can compile my project using terminal by typing:
g++ `pkg-config --cflags opencv` Hello.cpp -o Hello
and to be sure, this is what I get by running pkg-config --cflags opencv
on terminal:
-I/usr/local/Cellar/opencv/2.4.6.1/include/opencv
Upvotes: 0
Views: 6221
Reputation: 21
Dear i got the same error, please have a look here:
C++ linking error after upgrading to Mac OS X 10.9 / Xcode 5.0.1
very quick solution: add -stdlib=libstdc++ to the linking command.
Upvotes: 0
Reputation: 212969
You makefile does not have an explicit rule for building Hello.o so it is using a default rule. There are various ways to handle this but I would just change it to:
CXXFLAGS = -O2 -g -Wall -fmessage-length=0
SRCS = Hello.cpp
LIBS = -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_gpu
INCPATH = -I/usr/local/Cellar/opencv/2.4.6.1/include
LIBPATH = -L/usr/local/Cellar/opencv/2.4.6.1/lib
TARGET = Hello
$(TARGET): $(SRCS)
g++ $(CXXFLAGS) $(INCPATH) $(LIBPATH) -o $(TARGET) $(SRCS) $(LIBS)
all: $(TARGET)
clean:
rm -f $(TARGET)
Upvotes: 1
Reputation: 100836
I doubt this makefile ever worked, unless somehow the new version of MacOSX has moved those headers out of the standard location into a different location.
You are using the default built-in rules, as Paul R says, but you are not using the default make variables that go with those rules. I would write my makefile like this:
CXX = g++
CXXFLAGS = -O2 -g -Wall -fmessage-length=0
CPPFLAGS = -I/usr/local/Cellar/opencv/2.4.6.1/include
OBJS = Hello.o
LDFLAGS = -L/usr/local/Cellar/opencv/2.4.6.1/lib
LDLIBS = -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video \
-lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect \
-lopencv_contrib -lopencv_legacy -lopencv_gpu
TARGET = Hello
.PHONY: all
all: $(TARGET)
$(TARGET): $(OBJS)
$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
.PHONY: clean
clean:
rm -f $(OBJS) $(TARGET)
Upvotes: 3