(OpenCV4.1) /usr/bin/ld: 找不到 -lopencv_nonfree

Posted

技术标签:

【中文标题】(OpenCV4.1) /usr/bin/ld: 找不到 -lopencv_nonfree【英文标题】:(OpenCV4.1) /usr/bin/ld: cannot find -lopencv_nonfree 【发布时间】:2020-09-15 11:33:55 【问题描述】:

我在我的树莓派 3B 上按照https://www.pyimagesearch.com/2018/09/26/install-opencv-4-on-your-raspberry-pi/ 安装了 OpenCV 4.1。 我用这些 CMake 标志编译了 OpenCV:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_opencv_java=off -D BUILD_opencv_python2=OFF -D BUILD_opencv_python3=OFF -D ENABLE_PRECOMPILED_HEADERS=OFF -D BUILD_JPEG=OFF -D ENABLE_FAST_MATH=ON -D CMAKE_SHARED_LINKER_FLAGS=-latomic -D ENABLE_NEON=ON -D ENABLE_VFPV3=ON -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -D WITH_OPENCL=ON -D WITH_PTHREADS_PF=OFF -DEXTRA_C_FLAGS=-mcpu=cortex-a7 -mfpu=neon-vfpv4 -ftree-vectorize -mfloat-abi=hard -D EXTRA_CXX_FLAGS=-mcpu=cortex-a7 -mfpu=neon-vfpv4 -ftree-vectorize -mfloat-abi=hard -D BUILD_EXAMPLES=OFF -D BUILD_PERF_TESTS=OFF ..

当我编译我的项目时,我得到了这个错误:

/usr/bin/ld: impossibile trovare -lopencv_nonfree
collect2: error: ld returned 1 exit status
CMakeFiles/river_flow_velocity_estimation.dir/build.make:271: set di istruzioni per l'obiettivo "river_flow_velocity_estimation" non riuscito
make[2]: *** [river_flow_velocity_estimation] Errore 1
CMakeFiles/Makefile2:67: set di istruzioni per l'obiettivo "CMakeFiles/river_flow_velocity_estimation.dir/all" non riuscito
make[1]: *** [CMakeFiles/river_flow_velocity_estimation.dir/all] Errore 2
Makefile:83: set di istruzioni per l'obiettivo "all" non riuscito
make: *** [all] Errore 2

与此帖子相同的错误/usr/bin/ld: cannot find -lopencv_nonfree。

我是初学者,不太清楚可能是什么问题。 我不明白为什么即使我使用了标志OPENCV_ENABLE_NONFREE=ON,我的程序也找不到opencv_nonfree 模块。

有人知道怎么做吗?

编辑:我的 CMakeLists.txt

cmake_minimum_required(VERSION 3.5.1)
set (CMAKE_BUILD_TYPE Release)
#set (CMAKE_BUILD_TYPE Debug)
SET (CMAKE_MODULE_PATH "$CMAKE_SOURCE_DIR/cmake")
add_definitions(-std=c++0x)
project(river_flow_velocity_estimation)
set( OpenCV_DIR "/usr/share/OpenCV" )
set(OPENCV_ENABLE_NONFREE "Enable non-free algorithms" ON)
find_package( OpenCV 4.1.0 REQUIRED)
find_package( OpenMP REQUIRED)
include_directories(include $OpenCV_LIBRARIES $OpenCV_INCLUDE_DIRS  $catkin_INCLUDE_DIRS)

set (CMAKE_C_FLAGS "$CMAKE_C_FLAGS $OpenMP_C_FLAGS -mcpu=cortex-a53 -mfloat-abi=hard -funsafe-math-optimizations -mfpu=neon-fp-armv8")
set (CMAKE_CXX_FLAGS "$CMAKE_CXX_FLAGS $OpenMP_CXX_FLAGS -mcpu=cortex-a53 -mfloat-abi=hard -funsafe-math-optimizations -mfpu=neon-fp-armv8")
set (CMAKE_EXE_LINKER_FLAGS "$CMAKE_EXE_LINKER_FLAGS $OpenMP_EXE_LINKER_FLAGS")


file(GLOB SOURCES "src/*.cpp")
add_executable(river_flow_velocity_estimation $SOURCES)
target_link_libraries(river_flow_velocity_estimation opencv_nonfree $OpenCV_LIBS $catkin_LIBRARIES)

【问题讨论】:

你能给你的可执行文件target_link_libraryCMakeList.txt)吗? 是的,我已经编辑了帖子 我认为 opencv_nonfree 在 openCV 4.1 中不再存在。你能从target_link_libraries 中删除opencv_nonfree 并告诉你发生了什么 【参考方案1】:

opencv_nonfree 在 openCV 4.1 中不再存在。如果您从target_link_libraries 中删除opencv_nonfree,它应该可以工作。

仅供参考,它们现在从opencv_contrib 直接集成到modules/xfeatures2d/。使用您的标志OPENCV_ENABLE_NONFREE=ON,它们应该可用。

【讨论】:

以上是关于(OpenCV4.1) /usr/bin/ld: 找不到 -lopencv_nonfree的主要内容,如果未能解决你的问题,请参考以下文章

/usr/bin/ld: cannot find -llzma /usr/bin/ld: cannot find -lbz2

/usr/bin/ld: 找不到 -ll

/usr/bin/ld: 找不到 -lXext 依赖问题

gcc 错误“/usr/bin/ld: 找不到 -lstdc++”

/usr/bin/ld: 找不到共享库

/usr/bin/ld 找不到 -lbsd