兩個 OpenCV 版本:更新到一個破壞了另一個,儘管它們應該是分開的
大約一周前,我的 Linux 發行版(Antergos)從儲存庫(版本 3.14.1)安裝了最新版本的 OpenCV。為了兼容性,我將 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
,以及檢查我的路徑名是否正確。另外,我檢查了所有文件的包含語句中的兼容性問題,沒有發現任何問題。我假設包管理器對 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 是 void 的一個例外。我將其更改為 int 並進行了 return 語句
return 0;
,它似乎與 OpenCV 3 編譯得非常好。**注意:**我知道這兩個程序的程式碼都有效。我不是在尋求編碼方面的幫助,而是在問為什麼對 OpenCV 3 安裝的更新
/usr/include/
會在單獨的位置破壞 OpenCV 2 的自定義安裝。編輯:這是更複雜(圖像分割)程序的連結。
編輯:我已將更簡單程序的原始碼上傳到 Google Drive。它可以在這裡找到。
我已經解決了我面臨的問題。一個我不確定。另一個是我自己無知的結果。至於我在使用 OpenCV 2 和兩個程序中更簡單的程序時遇到的奇怪編譯錯誤,我不確定。但是,重新編譯 OpenCV 2 似乎已經解決了這個問題。
我犯的最大錯誤是我的makefile。我不知道 .bashrc 中定義的別名不會轉換為 makefile,並且與 bash 相比,makefile 的語法略有不同。在 bash
$(opencv2)
呼叫中,命令 opencv2 引用並在目前命令中使用其輸出。Using$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