我试图创建一个只显示图像的cpp文件:
#include <iostream>
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
int main(){
Mat img;
img = imread("img.jpg",1);
if (!img.data){
std::cout << "Could not open or find the image" << std::endl;
return -1;
}
namedWindow("my window", 1);
int key = 0;
while (key != 27){
imshow("my window", img);
waitKey(10);
}
destroyAllWindows();
return 0;
}
我正在使用这个Makefile:
CC=g++
CFLAGS=-W -Wall -ansi -pedantic -I/usr/include/opencv2
LDFLAGS=-lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_objdetect
EXEC=DetectRT
SRC= $(wildcard *.cpp)
OBJ= $(SRC:.cpp=.o)
all: $(EXEC)
$(EXEC): $(OBJ)
$(CC) -o $@ $^ $(LDFLAGS)
%.o: %.cpp
$(CC) -o $@ -c $< $(CFLAGS)
.PHONY: clean mrproper
clean:
rm -rf *.o
mrproper: clean
rm -rf $(EXEC)
但是,当我犯下错误时,我会收到错误:
Test.o: In function `main':
Test.cpp:(.text+0x46): undefined reference to `cv::imread(cv::String const&, int)'