简体   繁体   English

针对libuvc和opencv2的G ++未定义引用

[英]G++ undefined references for libuvc and opencv2

I'm trying to compile a C++ program which includes the libuvc.h header file and some more header files of opencv2. 我正在尝试编译包含libuvc.h头文件和opencv2的其他头文件的C ++程序。

The problem is, that I'm getting the following errors (undefinded references): 问题是,我遇到以下错误(未定义的引用):

root@Raspi_DataHarvest:~/Schreibtisch# g++ UVCCameraHandler.cpp -I/usr/local/include/libuvc -I/usr/local/include/opencv2

/tmp/ccvQZdkd.o: In function `UVCCameraHandler::start(int, CameraProperties, int)':
UVCCameraHandler.cpp:(.text+0x164): undefined reference to `uvc_init'
UVCCameraHandler.cpp:(.text+0x184): undefined reference to `uvc_perror'
UVCCameraHandler.cpp:(.text+0x204): undefined reference to `uvc_get_device_descriptor'
UVCCameraHandler.cpp:(.text+0x334): undefined reference to `uvc_open'
UVCCameraHandler.cpp:(.text+0x354): undefined reference to `uvc_perror'
UVCCameraHandler.cpp:(.text+0x3a8): undefined reference to `uvc_get_stream_ctrl_format_size'
UVCCameraHandler.cpp:(.text+0x3e8): undefined reference to `uvc_get_stream_ctrl_format_size'
UVCCameraHandler.cpp:(.text+0x40c): undefined reference to `uvc_print_diag'
UVCCameraHandler.cpp:(.text+0x424): undefined reference to `uvc_print_stream_ctrl'
UVCCameraHandler.cpp:(.text+0x43c): undefined reference to `uvc_perror'
UVCCameraHandler.cpp:(.text+0x46c): undefined reference to `uvc_stream_open_ctrl'
UVCCameraHandler.cpp:(.text+0x48c): undefined reference to `uvc_stream_start_iso'
UVCCameraHandler.cpp:(.text+0x4a4): undefined reference to `uvc_perror'
/tmp/ccvQZdkd.o: In function `UVCCameraHandler::grabFramesGrayscale(cv::Mat&, cv::Mat&)':
UVCCameraHandler.cpp:(.text+0x5c8): undefined reference to `uvc_stream_get_frame'
/tmp/ccvQZdkd.o: In function `UVCCameraHandler::grabFramesColor(cv::Mat&, cv::Mat&)':
UVCCameraHandler.cpp:(.text+0x864): undefined reference to `uvc_stream_get_frame'
UVCCameraHandler.cpp:(.text+0x92c): undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
/tmp/ccvQZdkd.o: In function `UVCCameraHandler::uvcFindDevice(uvc_context*, uvc_device**, int, int, char const*, int)':
UVCCameraHandler.cpp:(.text+0xae0): undefined reference to `uvc_get_device_list'
UVCCameraHandler.cpp:(.text+0xb10): undefined reference to `uvc_get_device_descriptor'
UVCCameraHandler.cpp:(.text+0xd0c): undefined reference to `uvc_get_device_descriptor'
/tmp/ccvQZdkd.o: In function `UVCCameraHandler::setProperties(CameraProperties)':
UVCCameraHandler.cpp:(.text+0xfb0): undefined reference to `uvc_get_gain'
UVCCameraHandler.cpp:(.text+0xff8): undefined reference to `uvc_set_gain'
UVCCameraHandler.cpp:(.text+0x103c): undefined reference to `uvc_set_ae_mode'
UVCCameraHandler.cpp:(.text+0x1050): undefined reference to `uvc_set_exposure_abs'
UVCCameraHandler.cpp:(.text+0x1068): undefined reference to `uvc_set_ae_mode'
/tmp/ccvQZdkd.o: In function `cv::String::String(char const*)':
UVCCameraHandler.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x60): undefined reference to `cv::String::allocate(unsigned int)'
/tmp/ccvQZdkd.o: In function `cv::String::~String()':
UVCCameraHandler.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
/tmp/ccvQZdkd.o: In function `cv::String::operator=(cv::String const&)':
UVCCameraHandler.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x30): undefined reference to `cv::String::deallocate()'
/tmp/ccvQZdkd.o: In function `cv::Mat::Mat(cv::Size_<int>, int, void*, unsigned int)':
UVCCameraHandler.cpp:(.text._ZN2cv3MatC2ENS_5Size_IiEEiPvj[_ZN2cv3MatC5ENS_5Size_IiEEiPvj]+0x140): undefined reference to `cv::error(int, cv::String const&, char const*, char const*, int)'
UVCCameraHandler.cpp:(.text._ZN2cv3MatC2ENS_5Size_IiEEiPvj[_ZN2cv3MatC5ENS_5Size_IiEEiPvj]+0x244): undefined reference to `cv::error(int, cv::String const&, char const*, char const*, int)'
/tmp/ccvQZdkd.o: In function `cv::Mat::~Mat()':
UVCCameraHandler.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x3c): undefined reference to `cv::fastFree(void*)'
/tmp/ccvQZdkd.o: In function `cv::Mat::operator=(cv::Mat const&)':
UVCCameraHandler.cpp:(.text._ZN2cv3MataSERKS0_[_ZN2cv3MataSERKS0_]+0x140): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/ccvQZdkd.o: In function `cv::Mat::create(int, int, int)':
UVCCameraHandler.cpp:(.text._ZN2cv3Mat6createEiii[_ZN2cv3Mat6createEiii]+0xc4): undefined reference to `cv::Mat::create(int, int const*, int)'
/tmp/ccvQZdkd.o: In function `cv::Mat::release()':
UVCCameraHandler.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x68): undefined reference to `cv::Mat::deallocate()'
/tmp/ccvQZdkd.o: In function `cv::Mat::operator()(cv::Rect_<int> const&) const':
UVCCameraHandler.cpp:(.text._ZNK2cv3MatclERKNS_5Rect_IiEE[_ZNK2cv3MatclERKNS_5Rect_IiEE]+0x24): undefined reference to `cv::Mat::Mat(cv::Mat const&, cv::Rect_<int> const&)'
collect2: error: ld returned 1 exit status

So, this looks to me like g++ does not find the location of the header files, but they are installed in the correct directory! 因此,在我看来,g ++找不到头文件的位置,但它们安装在正确的目录中!

root@Raspi_DataHarvest:~# find / | grep libuvc.h
/usr/local/include/libuvc/libuvc.h

root@Raspi_DataHarvest:~# find / | grep opencv2/opencv.hpp
/usr/local/include/opencv2/opencv.hpp

Furthermore, there's no effect using the absolute paths, like: 此外,使用绝对路径没有任何效果,例如:

#include "/usr/local/include/libuvc.h"
...

Does anyone know how to solve the reference errors? 有谁知道如何解决参考错误?

Try 尝试

g++ UVCCameraHandler.cpp -I/usr/local/include/libuvc -I/usr/local/include/opencv2 -luvc -lopencv

The most preferable 最可取的

g++ UVCCameraHandler.cpp `pkg-config --libs --cflags opencv` `pkg-config --libs --cflags lubuvc`

Building a C++ program is a three-step process: 构建C ++程序分为三个步骤:

  1. Editing the source 编辑源
  2. Compiling the source files into object files 将源文件编译成目标文件
  3. Linking the object files into the final executable 将目标文件链接到最终可执行文件

Modern compilers often use front-end programs (like eg GCC with the g++ program) that combine steps 2 and 3 into a single action. 现代编译器经常使用前端程序(例如,带有g++程序的GCC)将步骤2和3组合为一个动作。

In step 2 above, the header files are included. 在上面的步骤2中,包含头文件。

In step 3 you need to link with the actual libraries . 在第3步中,您需要链接到实际的 You do not do this, so the linker will complain that it can't find the functions you use. 您无需执行此操作,因此链接器会抱怨找不到您使用的功能。

Linking with the libraries using GCC is done with the -l (lower-case L) option, listing the library name. 使用-l (小写L)选项完成使用GCC与库的链接,列出库名称。 Like for example -lopencv to link with the OpenCV library. 例如, -lopencv与OpenCV库链接。

If the libraries are in a non-standard location (which /usr/local/lib usually is) then you need to tell the linker where to find the libraries as well. 如果库位于非标准位置(通常位于/usr/local/lib中),则需要告诉链接程序在哪里也可以找到这些库。 This is done with the -L option, similar to the -I option you already use to tell the compiler where to search for header-files. 这是通过-L选项完成的,类似于-I选项,您已经使用该选项告诉编译器在哪里搜索头文件。 For example -L/usr/local/lib . 例如-L/usr/local/lib

您需要链接到正确的库(假设您的库位于/usr/local/lib ):

g++ UVCCameraHandler.cpp -I/usr/local/include/libuvc -I/usr/local/include/opencv2 -L/usr/local/lib -luvc -lopencv_core

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM