您好,我使用C语言编写的CLion
项目使用 OpenCV库。
我已经使用CMake
对其进行了配置,并且编译并运行得非常好。但是我在目录中也有自己的Makefile
,现在我想添加到这个Makefile 支持OpenCV库。
以下是我添加到此Makefile中的行:
# libraries
# OpenCV
OPENCV_CFLAGS = `pkg-config —-cflags opencv`
OPENCV_LIBS = `pkg-config —-libs opencv`
然后:
$(TARGET): main.c $(LIBRARY) $(TEST_SOURCE_FILES)
$(CC) $(CFLAGS) -o $(TARGET) main.c $(LIBRARY) $(TEST_SOURCE_FILES) $(UNIT_TESTS_LIBRARY) $(OPENCV_LIBS) $(OPENCV_CFLAGS)
当我在做make -f make.txt
时,它无法编译,问题是:
fatal error: 'cv.h' file not found
#include <cv.h>
我也试着用这个:
# include headers
CFLAGS += -I/usr/local/include/opencv
但是,尽管发现cv.g还有另一个错误:
/usr/local/include/opencv/cv.h:63:10: fatal error: 'opencv2/core/core_c.h' file not found
#include "opencv2/core/core_c.h"
不,我把它更改为:
# include headers
CFLAGS += -I/usr/local/include
以及#include<cv.h>
到#include<opencv/cv.h>
没有关于找不到头文件的错误消息,但有些链接问题如下:
Undefined symbols for architecture x86_64:
"_cvCreateImage", referenced from:
答案 0 :(得分:0)
好的我已经解决了我在Makefile中创建的问题:
# include headers
# CFLAGS += -I/usr/local/include
# libraries
# OpenCV
OPENCV_LIBS = `pkg-config --cflags --libs opencv`
而不是编译目标时:
$(TARGET): main.c $(LIBRARY) $(TEST_SOURCE_FILES)
$(CC) $(CFLAGS) -o $(TARGET) main.c $(LIBRARY) $(TEST_SOURCE_FILES) $(UNIT_TESTS_LIBRARY) $(OPENCV_LIBS)