两个 OpenCV 版本:更新一个版本会破坏另一个版本,尽管它们应该是分开的

两个 OpenCV 版本:更新一个版本会破坏另一个版本,尽管它们应该是分开的

我的 Linux 发行版 (Antergos) 大约一周前从存储库安装了最新版本的 OpenCV(版本 3.14.1)。为了兼容性,我将 OpenCV 2(版本 2.4.13.5)安装在我的主目录中的单独文件夹中。

为了使 g++ 编译更容易,我在 .bashrc 文件中为每个版本创建了别名。此配置本质上允许我编译一个只有 main.cpp 文件的程序,通过使用g++ main.cpp $(opencv2)以下是我的 .bashrc 文件中的相关代码:

# 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<float> 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<float> const&, Imath_2_2::Vec2<float> const&, Imath_2_2::Vec2<float> const&, Imath_2_2::Vec2<float> 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<int, std::allocator<int> > 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<char, std::char_traits<char>, std::allocator<char> > 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::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(cv::FileNode const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)':
/usr/include/opencv2/core/cvstd.inl.hpp:156: undefined reference to `cv::read(cv::FileNode const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > 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>><int>(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<SWin, std::allocator<SWin> > const&, std::vector<std::vector<cv::Point3_<int>, std::allocator<cv::Point3_<int> > >, std::allocator<std::vector<cv::Point3_<int>, std::allocator<cv::Point3_<int> > > > > 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_<int>*, cv::Point_<int>*, cv::_InputArray const&)'
MeanShift.o: In function `MeanShift::showImage(cv::Mat, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > 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_<int>*, cv::Point_<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:829: undefined reference to `cv::operator-(cv::Mat const&, cv::Scalar_<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: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_<double> 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_<double> 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 进行编译,没有出现任何问题。例如,将$(opencv2)上面的 makefile 更改为 $(opencv3) 不会产生错误并且程序可以工作。

编辑:我是一名大学生,这些程序是计算机科学课程的作业。上面提到的比较复杂的程序不是我写的。它是我的教授提供的,是从另一所大学借来的。我必须修改它,但它处于可编译状态,除了 main.cpp 中的 main 为空之外。我将其更改为 int 并做了 return 语句return 0;,它似乎可以在 OpenCV 3 中完美编译。

笔记:我知道这两个程序的代码都有效。我不是在寻求编码方面的帮助,而是在问为什么对 OpenCV 3 安装的更新/usr/include/会破坏在单独位置中的 OpenCV 2 的自定义安装。

编辑:这里是更复杂(图像分割)程序的链接。

编辑:我已经将更简单的程序的源代码上传到Google Drive。可用这里

答案1

我已经解决了我面临的问题。有一个我不确定。另一个是我自己的无知造成的。至于我在使用 OpenCV 2 和两个程序中较简单的程序时遇到的奇怪编译错误,我不确定。然而,重新编译 OpenCV 2 似乎已经解决了这个问题。

我犯的最大错误是我的 makefile。我不知道 .bashrc 中定义的别名不会转换为 makefile,并且 makefile 与 bash 相比具有细微不同的语法。在 bash$(opencv2)调用中,命令 opencv2 在当前命令中引用并使用其输出。使用$opencv2将引用一个变量并返回它的值。在 makefile 中,情况并非如此。事实上,$(opencv2)返回一个名为 opencv2 的本地定义变量的值。命令可以由这些变量定义,但必须用反引号/标记括起来。下面是我更正后的 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

相关内容