1

I'm trying to build a cpp app which uses opencv libs which I've compiled myself.

This is my 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) 

Example of a lib file:

$ 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

In my header file I've included:

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

When I run petalinux-build -c appname or make appname I get:

| 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

Any idea why?

I'm currently migrating from Petalinux 2015 to 2018, and it works perfectly well in 2015.

William
  • 31
  • 1

1 Answers1

0

For the linker, the order of arguments may matter. Try

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

It's not a typo, I consciously put $(OPENCV_LIBS) twice, mainly because I don't want to start looking for the correct (recerse-dependency) order of the OpenCv libraries.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307