我正在使用 Qt-creator 在 nvidia jetson nano(在 ubuntu 18.04 LTS 下)上创建一个应用程序。为此,我创建了自己的库(名为 recolib),它使用 opencv(版本 3.4.6),然后在我的 Qt 应用程序项目中包含我的库。
该库编译正常,但是当我尝试编译应用程序时,它达到 100%,然后我收到以下错误:未定义引用 `cv::xfeatures2d::SURF::create(double, int, int, bool, bool)' .
请注意,调用此函数的类是我的库“recolib”的一部分。
我已经用 cmake 构建了 opencv,我启用了非自由模块并提供了正确的路径,并且 opencv 构建和安装都很好。
此外,该应用程序在 mac 和 ubuntu 虚拟机上运行良好。
以下是应用程序的 Cmakelist.txt 示例:
cmake_minimum_required(VERSION 3.0)
# Add folder where are supportive functions
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11 -pthread -lm")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11 -pthread -lm")
...
find_package(OpenCV REQUIRED)
if(OPENCV_XFEATURES2D_FOUND)
message("xfeatures2d found")
endif()
...
SET(RECOLIB_DIR "${PROJECT_SOURCE_DIR}/libs/recotracking-recolib")
include_directories("${RECOLIB_DIR}/include")
if(WIN32)
link_directories("${RECOLIB_DIR}/build/Debug")
else()
link_directories("${RECOLIB_DIR}/build/")
endif()
SET(RECOLIB_LIBRARY recolib)
include_directories(${OPENCV_INCLUDE_DIRS})
...
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
FILE(GLOB_RECURSE RES_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.qrc")
FILE(GLOB_RECURSE SRC_FILES "${SRC_FOLDER}/*.cpp")
FILE(GLOB_RECURSE UI_FILES "${SRC_FOLDER}/*.ui")
FILE(GLOB_RECURSE HDR_FILES "${HDR_FOLDER}/*.h")
link_directories(${OpenCV_LIBRARY_DIRS})
message("opencv libs: ${OpenCV_LIBRARIES}")
add_executable(${execName} ${OS_BUNDLE}# Expands to WIN32 or MACOS_BUNDLE depending on OS
${RES_FILES} ${SRC_FILES} ${UI_FILES} ${HDR_FILES} ${META_FILES_TO_INCLUDE}
)
...
# Add the Qt5 Widgets for linking
if (APPLE)
target_link_libraries(${execName}
${OpenCV_LIBRARIES}
${AppKit}
${CoreAudio}
${AudioToolbox}
Qt5::Core
Qt5::Gui
Qt5::QuickControls2
Qt5::MultimediaWidgets
Qt5::Multimedia
Qt5::MultimediaPrivate
Qt5::Widgets
Qt5::Sql
${RECOLIB_LIBRARY})
else()
target_link_libraries(${execName}
${OpenCV_LIBRARIES}
Qt5::Core
Qt5::Gui
Qt5::QuickControls2
Qt5::MultimediaWidgets
Qt5::Multimedia
#Qt5::MultimediaPrivate
Qt5::Widgets
Qt5::Sql
${RECOLIB_LIBRARY})
endif()
我在 Qt-creator 下执行它的输出如下:
Running "/usr/bin/cmake -E server --pipe=/tmp/cmake-Bg9h0e/socket --experimental" in /home/bookbeo-novatech/build-recotracking-app-Desktop-Release.
Starting to parse CMake project, using: "-DCMAKE_BUILD_TYPE:STRING=Release", "-DCMAKE_CXX_COMPILER:STRING=/usr/bin/g++", "-DCMAKE_C_COMPILER:STRING=/usr/bin/gcc", "-DCMAKE_PREFIX_PATH:STRING=/usr", "-DQT_QMAKE_EXECUTABLE:STRING=/usr/lib/qt5/bin/qmake".
-std=c++11 -pthread -lm
The C compiler identification is GNU 7.4.0
The CXX compiler identification is GNU 7.4.0
Check for working C compiler: /usr/bin/gcc
Check for working C compiler: /usr/bin/gcc -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: /usr/bin/g++
Check for working CXX compiler: /usr/bin/g++ -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Looking for pthread.h
Looking for pthread.h - found
Looking for pthread_create
Looking for pthread_create - not found
Looking for pthread_create in pthreads
Looking for pthread_create in pthreads - not found
Looking for pthread_create in pthread
Looking for pthread_create in pthread - found
Found Threads: TRUE
Found CUDA: /usr/local/cuda (found suitable exact version "10.0")
Found OpenCV: /usr/local (found version "3.4.6")
xfeatures2d found
opencv libs: opencv_calib3d;opencv_core;opencv_cudaarithm;opencv_cudabgsegm;opencv_cudacodec;opencv_cudafeatures2d;opencv_cudafilters;opencv_cudaimgproc;opencv_cudalegacy;opencv_cudaobjdetect;opencv_cudaoptflow;opencv_cudastereo;opencv_cudawarping;opencv_cudev;opencv_dnn;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_shape;opencv_stitching;opencv_superres;opencv_video;opencv_videoio;opencv_videostab;opencv_aruco;opencv_bgsegm;opencv_bioinspired;opencv_ccalib;opencv_cvv;opencv_datasets;opencv_dnn_objdetect;opencv_dpm;opencv_face;opencv_fuzzy;opencv_hfs;opencv_img_hash;opencv_line_descriptor;opencv_optflow;opencv_phase_unwrapping;opencv_plot;opencv_reg;opencv_rgbd;opencv_saliency;opencv_stereo;opencv_structured_light;opencv_surface_matching;opencv_text;opencv_tracking;opencv_xfeatures2d;opencv_ximgproc;opencv_xobjdetect;opencv_xphoto
Configuring done
Generating done
CMake Warning:
Manually-specified variables were not used by the project:
QT_QMAKE_EXECUTABLE
CMake Project was parsed successfully.
如您所见,除了 pthread 的一些问题(但似乎与主要问题无关),cmake 配置似乎不错。找到了 Opencv,也找到了 xfeatures2d。
但是当我构建应用程序时,在编译结束时我得到:
[ 94%] Building CXX object CMakeFiles/recotracking-app.dir/recotracking-app_autogen/mocs_compilation.cpp.o
[ 97%] Building CXX object CMakeFiles/recotracking-app.dir/recotracking-app_autogen/EWIEGA46WW/qrc_resources.cpp.o
[100%] Linking CXX executable recotracking-app
/home/bookbeo/recotracking-app/libs/recotracking-recolib/build/librecolib.a(PCB.cpp.o): In function `reco::PCB::load(cv::Mat const&, cv::Mat const&, cv::Mat const&, std::vector<reco::RecoPoi, std::allocator<reco::RecoPoi> >)':
CMakeFiles/recotracking-app.dir/build.make:1045: recipe for target 'recotracking-app' failed
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/recotracking-app.dir/all' failed
Makefile:83: recipe for target 'all' failed
/home/bookbeo-novatech/recotracking-app/libs/recotracking-recolib/src/PCB.cpp:47: undefined reference to `cv::xfeatures2d::SURF::create(double, int, int, bool, bool)'
collect2: error: ld returned 1 exit status
make[2]: *** [recotracking-app] Error 1
make[1]: *** [CMakeFiles/recotracking-app.dir/all] Error 2
make: *** [all] Error 2
10:51:49: Le processus "/usr/bin/cmake" s'est terminé avec le code 2.
Erreur lors de la compilation/déploiement du projet recotracking-app (kit : Desktop)
When executing step "CMake Build"
10:51:49: Temps écoulé : 06:59.
我已经尝试重新构建opencv,它没有改变任何东西,并且似乎找到了模块xfeatures2d,所以我不知道这个错误来自哪里。
如果您有任何想法,我将不胜感激。
提前致谢。