私のLinuxディストリビューション(Antergos)は、約1週間前にリポジトリに最新バージョンのOpenCV(バージョン3.14.1)をインストールしました。互換性のために、ホームディレクトリの別のフォルダにOpenCV 2(バージョン2.4.13.5)をインストールしました。
g++のコンパイルを容易にするために、.bashrcファイルに各バージョンのエイリアスを作成しました。この設定では、デフォルトでg++ main.cpp $(opencv2)
.bashrcファイル内の関連コードを次のように使用して、main.cppファイルのみでプログラムをコンパイルできます。
# 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が空であることを除けばコンパイル可能な状態です。 intに変更してreturnステートメントを作成したreturn 0;
ので、OpenCV 3では完全にコンパイルされるようです。
メモ:両方のプログラムのコードが動作することを知っています。コーディングヘルプを探すのではなく、OpenCV 3インストールの更新が/usr/include/
別の場所にあるOpenCV 2のカスタムインストールが中断される理由を尋ねています。
編集する:ここより複雑な(画像分割)プログラムへのリンク。
編集:より簡単なプログラムのソースコードをGoogleドライブにアップロードしました。利用可能ここ。
答え1
私が直面した問題を解決しました。わからないことが一つあります。もう一つは私の無知によって引き起こされました。 OpenCV 2と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