对预编译的opencv 2.4的未定义引用

时间:2019-01-30 13:11:03

标签: opencv makefile yocto petalinux

我正在尝试构建一个使用我自己编译的opencv库的cpp应用程序。

这是我的Makefile:

APP = appname

APP_OBJS = appname.o

OPENCV_DIR = /{path}/project-spec/meta-user/recipes-apps/opencv-vs/files    
OPENCV_LIBS = -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy   -lopencv_flann

CC = g++ 

CXXFLAGS += -std=c++11

all: build install

build: $(APP)

$(APP): $(APP_OBJS)
    $(CXX)  -o $@ $(LDFLAGS) -L$(OPENCV_DIR)/lib $(OPENCV_LIBS) $(APP_OBJS) $(LDLIBS)

clean:
    -rm -f $(APP) *.elf *.gdb *.o

.PHONY: install image

install: $(APP)
    $(TARGETINST) -d $(APP) /bin/$(APP)

%.o: %.cpp
    $(CXX) -c -o $@ $< $(CXXFLAGS) -I$(OPENCV_DIR)/include -I$(LIBISS_DIR) 

lib文件示例:

$ file libopencv_stitching.so.2.4.11
libopencv_stitching.so.2.4.11: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, not stripped

我的头文件中包含:

#include "opencv2/opencv.hpp"
#include "opencv2/nonfree/nonfree.hpp"

当我运行 petalinux-build -c appname make appname 时,我得到:

| appname.cpp:419: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
| appname.cpp:419: undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
| ...core.hpp:2219: undefined reference to `cv::noArray()
| /path/include/opencv2/core/operations.hpp:2607: undefined reference to `cv::fastFree(void*)'
| etc
| etc
| etc
| collect2: error: ld returned 1 exit status
| ERROR: oe_runmake failed
| make: *** [Makefile:24: appname] Error 1

知道为什么吗?

我目前正在从Petalinux 2015迁移到2018,并且在2015年运行良好。

1 个答案:

答案 0 :(得分:0)

对于链接器,参数的顺序可能很重要。尝试

$(APP): $(APP_OBJS)
    $(CXX)  -o $@ $(LDFLAGS) $(APP_OBJS) -L$(OPENCV_DIR)/lib $(OPENCV_LIBS) $(OPENCV_LIBS)   $(LDLIBS)
  

这不是错字,我有意识地将$(OPENCV_LIBS)放在了两次,主要是因为我不想开始寻找OpenCv库的正确(依赖于依赖)顺序。