大约一周前,我的Linux发行版(Antergos)从存储库(3.14.1版)安装了最新版本的OpenCV。为了兼容性,我在主目录中的一个单独文件夹中安装了OpenCV 2(版本2.4.13.5)。
为了简化g++编译,我在.bashrc文件中为每个版本创建了别名。这个配置基本上允许我通过使用下面的main.cpp文件中的相关代码来编译,比如说一个只有一个g++ main.cpp $(opencv2)
文件的程序:
# Programming Related Aliases
# OpenCV
alias opencv3='pkg-config --cflags --libs opencv' # OpenCV 3
opencv2prefix="$HOME/separate-libs/opencv2/release/installed" # Prefix that serves as the basis for the pathname of the OpenCV 2 directory.
export PKG_CONFIG_PATH="$opencv2prefix/lib/pkgconfig"
export LD_LIBRARY_PATH="$opencv2prefix/lib"
alias opencv2="pkg-config --cflags --libs opencv2" # OpenCV 2 lib, include and runtime specifications for OpenCV 2. Defined in PKG_CONFIG_PATH.
直到今天早些时候,我用OpenCV 2配置编译了一个更大的程序(执行图像分割),这一设置才得以完美地工作。一开始,我以为在从源代码编译OpenCV 2时,我忘记了一个必要的构建选项。然而,为了检查我的理智,我试着编译了一个程序,在前面提到的更新之前,我已经成功地用OpenCV 2编译了这个程序。其结果如下:
/usr/bin/ld: warning: libImath-2_2.so.12, needed by /home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libIlmImf-2_2.so.22, needed by /home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libIex-2_2.so.12, needed by /home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libHalf.so.12, needed by /home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libIlmThread-2_2.so.12, needed by /home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::globalThreadCount()'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::ChannelList::insert(char const*, Imf_2_2::Channel const&)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::InputFile::header() const'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::hasChromaticities(Imf_2_2::Header const&)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::OutputFile::writePixels(int)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::InputFile::setFrameBuffer(Imf_2_2::FrameBuffer const&)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::InputFile::readPixels(int, int)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::Channel::Channel(Imf_2_2::PixelType, int, int, bool)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::Slice::Slice(Imf_2_2::PixelType, char*, unsigned long, unsigned long, int, int, double, bool, bool)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::OutputFile::setFrameBuffer(Imf_2_2::FrameBuffer const&)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::Header::dataWindow() const'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::Header::channels()'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `half::_eLut'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::Header::channels() const'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::Header::~Header()'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::Header::Header(int, int, float, Imath_2_2::Vec2 const&, float, Imf_2_2::LineOrder, Imf_2_2::Compression)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::InputFile::InputFile(char const*, int)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::OutputFile::OutputFile(char const*, Imf_2_2::Header const&, int)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::FrameBuffer::insert(char const*, Imf_2_2::Slice const&)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::ChannelList::findChannel(char const*) const'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::chromaticities(Imf_2_2::Header const&)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `half::convert(int)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::Chromaticities::Chromaticities(Imath_2_2::Vec2 const&, Imath_2_2::Vec2 const&, Imath_2_2::Vec2 const&, Imath_2_2::Vec2 const&)'
/home/kvasir/separate-libs/opencv2/release/installed/lib/libopencv_highgui.so: undefined reference to `Imf_2_2::OutputFile::~OutputFile()'
collect2: error: ld returned 1 exit status
我试着运行sudo ldconfig
,并检查我的路径名是否正确。此外,我在所有文件的include语句中检查了兼容性问题,没有发现任何问题。我认为包管理器对OpenCV 3安装的更新是导致一切混乱的原因。但如果是这样,为什么?显然,如果OpenCV安装在同一个文件夹中,我可以理解。但两者似乎是完全分开的,而且彼此都不知道。我唯一的猜测就是用pkg-config。
当我试图编译包含目标文件和更复杂代码的图像分割程序时,我会得到:
/tmp/ccpvnIWK.o: In function `main':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/main.cpp:37: undefined reference to `cv::waitKey(int)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/main.cpp:51: undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/main.cpp:74: undefined reference to `cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector > const&)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/main.cpp:75: undefined reference to `cv::namedWindow(cv::String const&, int)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/main.cpp:76: undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/main.cpp:77: undefined reference to `cv::waitKey(int)'
/tmp/ccpvnIWK.o: In function `cv::String::String(char const*)':
/usr/include/opencv2/core/cvstd.hpp:602: undefined reference to `cv::String::allocate(unsigned long)'
/tmp/ccpvnIWK.o: In function `cv::String::~String()':
/usr/include/opencv2/core/cvstd.hpp:648: undefined reference to `cv::String::deallocate()'
/tmp/ccpvnIWK.o: In function `cv::String::operator=(cv::String const&)':
/usr/include/opencv2/core/cvstd.hpp:656: undefined reference to `cv::String::deallocate()'
/tmp/ccpvnIWK.o: In function `cv::Mat::Mat(cv::Mat const&)':
/usr/include/opencv2/core/mat.inl.hpp:490: undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/ccpvnIWK.o: In function `cv::Mat::~Mat()':
/usr/include/opencv2/core/mat.inl.hpp:704: undefined reference to `cv::fastFree(void*)'
/tmp/ccpvnIWK.o: In function `cv::Mat::release()':
/usr/include/opencv2/core/mat.inl.hpp:816: undefined reference to `cv::Mat::deallocate()'
/tmp/ccpvnIWK.o: In function `cv::Mat::operator=(cv::Mat&&)':
/usr/include/opencv2/core/mat.inl.hpp:1383: undefined reference to `cv::fastFree(void*)'
/tmp/ccpvnIWK.o: In function `cv::String::String(std::__cxx11::basic_string, std::allocator > const&)':
/usr/include/opencv2/core/cvstd.inl.hpp:83: undefined reference to `cv::String::allocate(unsigned long)'
Loader.o: In function `void cv::operator>>, std::allocator > >(cv::FileNode const&, std::__cxx11::basic_string, std::allocator >&)':
/usr/include/opencv2/core/cvstd.inl.hpp:156: undefined reference to `cv::read(cv::FileNode const&, std::__cxx11::basic_string, std::allocator >&, std::__cxx11::basic_string, std::allocator > const&)'
Loader.o: In function `Loader::loadControlParameters(ControlParameters&)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:16: undefined reference to `cv::FileStorage::FileStorage(cv::String const&, int, cv::String const&)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:17: undefined reference to `cv::FileStorage::isOpened() const'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:20: undefined reference to `cv::waitKey(int)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:24: undefined reference to `cv::FileStorage::operator[](char const*) const'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:25: undefined reference to `cv::FileStorage::operator[](char const*) const'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:26: undefined reference to `cv::FileStorage::operator[](char const*) const'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:27: undefined reference to `cv::FileStorage::operator[](char const*) const'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:16: undefined reference to `cv::FileStorage::~FileStorage()'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:16: undefined reference to `cv::FileStorage::~FileStorage()'
Loader.o: In function `Loader::loadOriginalImage(ControlParameters const&)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/Loader.cpp:35: undefined reference to `cv::imread(cv::String const&, int)'
Loader.o: In function `void cv::operator>>(cv::FileNode const&, int&)':
/usr/include/opencv2/core/persistence.hpp:1238: undefined reference to `cv::read(cv::FileNode const&, int&, int)'
MeanShift.o: In function `cv::operator*=(cv::Mat&, double const&)':
/usr/include/opencv2/core/operations.hpp:254: undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
MeanShift.o: In function `MeanShift::segmentUsingLAB(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:22: undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:24: undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:26: undefined reference to `cv::split(cv::Mat const&, cv::Mat*)'
MeanShift.o: In function `MeanShift::segmentUsingLAB(cv::Mat, unsigned int)':
/usr/include/opencv2/core.hpp:788: undefined reference to `cv::noArray()'
MeanShift.o: In function `MeanShift::segmentUsingLAB(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:28: undefined reference to `cv::normalize(cv::_InputArray const&, cv::_InputOutputArray const&, double, double, int, int, cv::_InputArray const&)'
MeanShift.o: In function `MeanShift::segmentUsingLAB(cv::Mat, unsigned int)':
/usr/include/opencv2/core.hpp:788: undefined reference to `cv::noArray()'
MeanShift.o: In function `MeanShift::segmentUsingLAB(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:29: undefined reference to `cv::normalize(cv::_InputArray const&, cv::_InputOutputArray const&, double, double, int, int, cv::_InputArray const&)'
MeanShift.o: In function `MeanShift::segmentUsingLAB(cv::Mat, unsigned int)':
/usr/include/opencv2/core.hpp:788: undefined reference to `cv::noArray()'
MeanShift.o: In function `MeanShift::segmentUsingLAB(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:30: undefined reference to `cv::normalize(cv::_InputArray const&, cv::_InputOutputArray const&, double, double, int, int, cv::_InputArray const&)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:32: undefined reference to `cv::merge(cv::Mat const*, unsigned long, cv::_OutputArray const&)'
MeanShift.o: In function `MeanShift::segmentUsingHLS(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:44: undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:46: undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:48: undefined reference to `cv::split(cv::Mat const&, cv::Mat*)'
MeanShift.o: In function `MeanShift::segmentUsingHLS(cv::Mat, unsigned int)':
/usr/include/opencv2/core.hpp:788: undefined reference to `cv::noArray()'
MeanShift.o: In function `MeanShift::segmentUsingHLS(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:50: undefined reference to `cv::normalize(cv::_InputArray const&, cv::_InputOutputArray const&, double, double, int, int, cv::_InputArray const&)'
MeanShift.o: In function `MeanShift::segmentUsingHLS(cv::Mat, unsigned int)':
/usr/include/opencv2/core.hpp:788: undefined reference to `cv::noArray()'
MeanShift.o: In function `MeanShift::segmentUsingHLS(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:51: undefined reference to `cv::normalize(cv::_InputArray const&, cv::_InputOutputArray const&, double, double, int, int, cv::_InputArray const&)'
MeanShift.o: In function `MeanShift::segmentUsingHLS(cv::Mat, unsigned int)':
/usr/include/opencv2/core.hpp:788: undefined reference to `cv::noArray()'
MeanShift.o: In function `MeanShift::segmentUsingHLS(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:52: undefined reference to `cv::normalize(cv::_InputArray const&, cv::_InputOutputArray const&, double, double, int, int, cv::_InputArray const&)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:54: undefined reference to `cv::merge(cv::Mat const*, unsigned long, cv::_OutputArray const&)'
MeanShift.o: In function `MeanShift::segmentUsingRGB(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:74: undefined reference to `cv::countNonZero(cv::_InputArray const&)'
MeanShift.o: In function `MeanShift::segmentUsingRGB(cv::Mat, unsigned int)':
/usr/include/opencv2/core.hpp:788: undefined reference to `cv::noArray()'
MeanShift.o: In function `MeanShift::segmentUsingRGB(cv::Mat, unsigned int)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:121: undefined reference to `cv::normalize(cv::_InputArray const&, cv::_InputOutputArray const&, double, double, int, int, cv::_InputArray const&)'
MeanShift.o: In function `MeanShift::segmentFromFeatureSpace(cv::Mat const&, unsigned int, std::vector > const&, std::vector, std::allocator > >, std::allocator, std::allocator > > > > const&)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:145: undefined reference to `cv::split(cv::Mat const&, cv::Mat*)'
MeanShift.o: In function `MeanShift::getChannelsRanges(cv::Mat, int*, SImgDims&)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:204: undefined reference to `cv::split(cv::Mat const&, cv::Mat*)'
MeanShift.o: In function `MeanShift::getChannelsRanges(cv::Mat, int*, SImgDims&)':
/usr/include/opencv2/core.hpp:819: undefined reference to `cv::noArray()'
MeanShift.o: In function `MeanShift::getChannelsRanges(cv::Mat, int*, SImgDims&)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:214: undefined reference to `cv::minMaxLoc(cv::_InputArray const&, double*, double*, cv::Point_*, cv::Point_*, cv::_InputArray const&)'
MeanShift.o: In function `MeanShift::showImage(cv::Mat, std::__cxx11::basic_string, std::allocator > const&)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:789: undefined reference to `cv::namedWindow(cv::String const&, int)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:795: undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:797: undefined reference to `cv::waitKey(int)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:800: undefined reference to `cv::destroyWindow(cv::String const&)'
MeanShift.o: In function `MeanShift::makeIt8bit(cv::Mat)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:811: undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
MeanShift.o: In function `MeanShift::standardization(cv::Mat const&)':
/usr/include/opencv2/core.hpp:819: undefined reference to `cv::noArray()'
MeanShift.o: In function `MeanShift::standardization(cv::Mat const&)':
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:827: undefined reference to `cv::minMaxLoc(cv::_InputArray const&, double*, double*, cv::Point_*, cv::Point_*, cv::_InputArray const&)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:829: undefined reference to `cv::operator-(cv::Mat const&, cv::Scalar_ const&)'
/home/kvasir/Documents/PolytechSchoolWork/2018 Spring (algorithms, software engineering, computer vision, artificial intelligence, computer architecture and organization)/computer-vision/projects/3rd-assignment/MeanShift/MeanShift.cpp:829: undefined reference to `cv::operator*(cv::MatExpr const&, double)'
MeanShift.o: In function `cv::Mat::Mat(int, int const*, int)':
/usr/include/opencv2/core/mat.inl.hpp:446: undefined reference to `cv::Mat::create(int, int const*, int)'
MeanShift.o: In function `cv::Mat::Mat(int, int const*, int, cv::Scalar_ const&)':
/usr/include/opencv2/core/mat.inl.hpp:454: undefined reference to `cv::Mat::create(int, int const*, int)'
/usr/include/opencv2/core/mat.inl.hpp:455: undefined reference to `cv::Mat::operator=(cv::Scalar_ const&)'
MeanShift.o: In function `cv::Mat::create(int, int, int)':
/usr/include/opencv2/core/mat.inl.hpp:796: undefined reference to `cv::Mat::create(int, int const*, int)'
collect2: error: ld returned 1 exit status
make: *** [makefile:6: segmentation] Error 1
这个输出特别让我感到奇怪的是,看起来*.o文件在/usr/include/opencv2
中查找函数定义。如果它是与$opencv2
一起调用的,那么它不应该在/home/kvasir/separate-libs/opencv2/release/installed/*
中显示吗?
生成上述错误的makefile如下所示:
segmentation : main.cpp Loader.o MeanShift.o ControlParameters.h defs.h
g++ -g -o segmentation main.cpp Loader.o MeanShift.o $(opencv2)
Loader.o : Loader.cpp Loader.h
g++ -g -c Loader.cpp
MeanShift.o : MeanShift.cpp MeanShift.h
g++ -g -c MeanShift.cpp
clean:
rm segmentation *.o
我还尝试用OpenCV 2版本编译对象文件,但没有效果。我的下一步可能是重新安装OpenCV 2,但是,我很好奇为什么会发生这种情况,以及是否有任何方法来修复和防止将来发生这种情况。
此外,这两个程序都成功地用OpenCV 3编译,没有问题。例如,将上述makefile中的$(opencv2)
更改为$(opencv3)不会导致错误和工作程序。
编辑:我是一名大学生,这些程序是计算机科学课程的作业。上面提到的更复杂的程序不是我写的。它是由我的教授提供,并从另一所大学借来的。我必须修改它,但是它处于可编译状态,只有main.cpp中的main是空的。我将其改为int,并使返回语句return 0;
,它似乎在OpenCV 3中编译得非常好。
注意:我知道这两个程序的代码都能工作。我不是在寻求编码方面的帮助,但我想问的是,为什么在/usr/include/
中对OpenCV 3安装的更新会使OpenCV 2的自定义安装在一个单独的位置出现故障。
编辑:这里是一个链接到更复杂的(图像分割)程序。
编辑:我已经上传了更简单的程序的源代码到谷歌驱动器。它是可用的这里。
发布于 2018-03-22 20:16:33
我已经解决了我面临的问题。一个我不确定的。另一个是我自己无知的结果。至于我在OpenCV 2中遇到的奇怪的编译错误,以及这两个程序中比较简单的一个,我不确定。然而,重新编译OpenCV 2似乎解决了这个问题。
我犯的最大的错误是用我的makefile。我不知道在.bashrc中定义的别名不会转换为makefile,而且makefile与bash有着细微不同的语法。在bash中,$(opencv2)
调用命令opencv2引用并在当前命令中使用其输出。使用$opencv2
将引用一个变量并返回它的值。在制作文件中,情况并非如此。实际上,$(opencv2)
返回名为opencv2的本地定义变量的值。命令可以由这些变量定义,但必须被backticks/grave标记包围。下面是我更正的makefile:
OPENCV=`pkg-config --cflags --libs opencv2`
segmentation : main.cpp Loader.o MeanShift.o ControlParameters.h defs.h
g++ -g main.cpp Loader.o MeanShift.o $(OPENCV) -o segmentation
Loader.o : Loader.cpp Loader.h
g++ -g -c Loader.cpp $(OPENCV)
MeanShift.o : MeanShift.cpp MeanShift.h
g++ -g -c MeanShift.cpp $(OPENCV)
clean:
rm segmentation *.o
https://unix.stackexchange.com/questions/432476
复制相似问题