nihui/opencv-mobile

libhighgui.a was not linked in the CMake project

ugtony opened this issue · 0 comments

Hi,
I was able to use some OpenCV functions in my CMake project after I followed the "How-to-build your custom package" steps in README.md. However, problems occurs when I used cv::cvtColor(...).

main.cpp:(.text+0xd0): undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'

I printed out the make command by executing make VERBOSE=1 and realized libopencv_highgui.a was not included in the g++ command

/usr/local/linaro-aarch64-2018.08-gcc8.2/bin//aarch64-linux-gnu-g++     CMakeFiles/hello_audrey.dir/main.cpp.o  -o hello_audrey -Wl,-rpath,/host/sutony/tmp/opencv/build libalign.so /host/sutony/git/opencv-mobile/opencv-4.5.3/build/install/lib/libopencv_calib3d.a /host/sutony/git/opencv-mobile/opencv-4.5.3/build/install/lib/libopencv_core.a /host/sutony/git/opencv-mobile/opencv-4.5.3/build/install/lib/libopencv_features2d.a /host/sutony/git/opencv-mobile/opencv-4.5.3/build/install/lib/libopencv_flann.a /host/sutony/git/opencv-mobile/opencv-4.5.3/build/install/lib/libopencv_imgproc.a /host/sutony/git/opencv-mobile/opencv-4.5.3/build/install/lib/libopencv_core.a -ldl -lm -lpthread -lrt /host/sutony/AMB/linaro-aarch64-2018.08-gcc8.2/aarch64-linux-gnu/libc/usr/lib/libgomp.so /host/sutony/AMB/linaro-aarch64-2018.08-gcc8.2/aarch64-linux-gnu/libc/usr/lib/libpthread.so 

If I manually added libopencv_highgui.a to the g++ command or added it to the CMakeList, it works.

find_package(OpenMP REQUIRED)
set(OpenCV_DIR /path/to/opencv-4.5.3/build/install/lib/cmake/opencv4)
find_package(OpenCV REQUIRED)

add_executable(main main.cpp)
target_link_libraries(main /path/to/opencv-4.5.3/build/install/lib/libopencv_highgui.a ${OpenCV_LIBS} OpenMP::OpenMP_CXX )

I think it would be better to change something in opencv-4.5.3/build/install/lib/cmake/opencv4 to make libopencv_highgui.a linked automatically, but it is beyond my ability. Could you help? Thanks.