链接静态OpenCV库eclipse CDT

时间:2016-11-25 18:47:12

标签: c++ eclipse opencv static-libraries eclipse-cdt

我正在尝试将OpenCV静态库链接到Eclipse中的c ++项目,但我无法使其工作。这是我尝试链接库的方式:

enter image description here

enter image description here

以下是代码:

    #include <stdio.h>
    #include <iostream>
    #include "opencv2/core.hpp"
    #include "opencv2/features2d.hpp"
    #include "opencv2/highgui.hpp"
    #include "opencv2/opencv.hpp"
    #include "opencv2/xfeatures2d.hpp"

    using namespace std;
    using namespace cv;
    using namespace cv::xfeatures2d;

    void readme();
    bool response_comparator(const KeyPoint& p1, const KeyPoint& p2);
    void write(Mat m);

    int main( int argc, char** argv ) {

        //Checks if the number of arguments is correct
        if ( argc != 2 ) {
            readme();
            return -1;
        }

        //Reads the image and converts it to gray
        Mat img = imread( argv[1], IMREAD_GRAYSCALE );

        //Checks wether is possible to read the image
        if (!img.data) {
            std::cout<< " --(!) Error reading the image. " << std::endl;
            return -1;
        }

        //Detect the keypoints using SURF Detector
        int minHessian = 400;
        Ptr<SURF> detector = SURF::create( minHessian );
        std::vector<KeyPoint> keypoints;
        detector->detect( img, keypoints );

        //Sort key points according to their response and gets the 10 strongest
        std::sort( keypoints.begin(), keypoints.end(), response_comparator );
        std::vector<KeyPoint> strongest( keypoints.begin(), keypoints.begin() + 10 );

        //Computes the descriptors (or features) of the 10 strongest points
        Mat descriptors;
        detector->compute( img, strongest, descriptors );

        //Creates a KD Search Tree with those descriptors
        cv::flann::KDTreeIndexParams indexParams;
        cv::flann::Index kdTree(descriptors, indexParams);

        //=====================================================
        //      The following part is for testing purposes
        //=====================================================

        //Prints descriptors to a file in the same directory as the exe
        write(descriptors);

        //Draw the 10 strongest keypoints
        Mat img_keypoints;
        drawKeypoints( img, strongest, img_keypoints, Scalar(9, 232, 61), DrawMatchesFlags::DRAW_RICH_KEYPOINTS );

        //Show detected (drawn) keypoints
        imshow( "Keypoints", img_keypoints );

        //Wait for user to press a key to finish the program
        waitKey(0);

        return 0;
    }

    void readme() {
        std::cout << " Usage: ./ShortProject <path/to/image>" << std::endl;
    }

    bool response_comparator(const KeyPoint& p1, const KeyPoint& p2) {
        return p1.response > p2.response;
    }

    void write(Mat m) {
        //Open the file
        cv::FileStorage file("./descriptors.txt", cv::FileStorage::WRITE);

        //Write each row
        file << "Descriptors";
        file << "{";

        String name;
        for(int row = 0; row < m.rows; row++) {
            name = "row" + std::to_string(row + 1);
            file << name << m.row(row);
        }

        file << "}";

        //Release the file
        file.release();
    }

这些是我在尝试构建项目时收到的消息:

19:23:22 **** Incremental Build of configuration Release for project SURFFeatures ****
make all 
Building file: ../src/SURFFeatures.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/SURFFeatures.d" MT"src/SURFFeatures.o" -o "src/SURFFeatures.o" "../src/SURFFeatures.cpp"
Finished building: ../src/SURFFeatures.cpp

Building target: SURFFeatures
Invoking: MacOS X C++ Linker
g++  -o "SURFFeatures"  ./src/SURFFeatures.o   
Undefined symbols for architecture x86_64:
"cv::FileStorage::release()", referenced from:
  write(cv::Mat) in SURFFeatures.o
"cv::FileStorage::FileStorage(cv::String const&, int, cv::String const&)", referenced from:
  write(cv::Mat) in SURFFeatures.o
"cv::FileStorage::~FileStorage()", referenced from:
  write(cv::Mat) in SURFFeatures.o
"cv::xfeatures2d::SURF::create(double, int, int, bool, bool)", referenced from:
  _main in SURFFeatures.o
"cv::drawKeypoints(cv::_InputArray const&, std::__1::vector<cv::KeyPoint, std::__1::allocator<cv::KeyPoint> > const&, cv::_InputOutputArray const&, cv::Scalar_<double> const&, int)", referenced from:
  _main in SURFFeatures.o
"cv::Mat::deallocate()", referenced from:
  _main in SURFFeatures.o
  write(cv::Mat) in SURFFeatures.o
"cv::Mat::copySize(cv::Mat const&)", referenced from:
  _main in SURFFeatures.o
"cv::Mat::Mat(cv::Mat const&, cv::Range const&, cv::Range const&)", referenced from:
  write(cv::Mat) in SURFFeatures.o
"cv::error(int, cv::String const&, char const*, char const*, int)", referenced from:
  write(cv::Mat) in SURFFeatures.o
"cv::flann::IndexParams::~IndexParams()", referenced from:
  _main in SURFFeatures.o
"cv::flann::KDTreeIndexParams::KDTreeIndexParams(int)", referenced from:
  _main in SURFFeatures.o
"cv::flann::Index::Index(cv::_InputArray const&, cv::flann::IndexParams const&, cvflann::flann_distance_t)", referenced from:
  _main in SURFFeatures.o
"cv::flann::Index::~Index()", referenced from:
  _main in SURFFeatures.o
"cv::write(cv::FileStorage&, cv::String const&, cv::Mat const&)", referenced from:
  write(cv::Mat) in SURFFeatures.o
"cv::String::deallocate()", referenced from:
  _main in SURFFeatures.o
  write(cv::Mat) in SURFFeatures.o
"cv::String::allocate(unsigned long)", referenced from:
  _main in SURFFeatures.o
  write(cv::Mat) in SURFFeatures.o
"cv::imread(cv::String const&, int)", referenced from:
  _main in SURFFeatures.o
"cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
  _main in SURFFeatures.o
"cv::noArray()", referenced from:
  _main in SURFFeatures.o
"cv::waitKey(int)", referenced from:
  _main in SURFFeatures.o
"cv::fastFree(void*)", referenced from:
  _main in SURFFeatures.o
  write(cv::Mat) in SURFFeatures.o
"cv::operator<<(cv::FileStorage&, cv::String const&)", referenced from:
  write(cv::Mat) in SURFFeatures.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [SURFFeatures] Error 1

19:23:23 Build Finished (took 1s.13ms)

我做错了什么?在此先感谢,任何帮助将不胜感激:)

修改

在添加contrib模块和xfeatures2d库之后,我遇到了很长的这类错误列表:

    "_ippicvsMaxEvery_32f", referenced from:
      cv::hal::max32f(float const*, unsigned long, float const*, unsigned long, float*, unsigned long, int, int, void*) in libopencv_core.a(arithm.cpp.o)
    "_ippicvsMaxEvery_64f", referenced from:
      cv::hal::max64f(double const*, unsigned long, double const*, unsigned long, double*, unsigned long, int, int, void*) in libopencv_core.a(arithm.cpp.o)
    "_ippicvsMaxEvery_8u", referenced from:
      cv::hal::max8u(unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned char*, unsigned long, int, int, void*) in libopencv_core.a(arithm.cpp.o)
    "_ippicvsMinEvery_16u", referenced from:
      cv::hal::min16u(unsigned short const*, unsigned long, unsigned short const*, unsigned long, unsigned short*, unsigned long, int, int, void*) in libopencv_core.a(arithm.cpp.o)
    "_ippicvsMinEvery_32f", referenced from:
      cv::hal::min32f(float const*, unsigned long, float const*, unsigned long, float*, unsigned long, int, int, void*) in libopencv_core.a(arithm.cpp.o)
    "_ippicvsMinEvery_64f", referenced from:
      cv::hal::min64f(double const*, unsigned long, double const*, unsigned long, double*, unsigned long, int, int, void*) in libopencv_core.a(arithm.cpp.o)
    "_ippicvsMinEvery_8u", referenced from:
      cv::hal::min8u(unsigned char const*, unsigned long, unsigned char const*, unsigned long, unsigned char*, unsigned long, int, int, void*) in libopencv_core.a(arithm.cpp.o)
    "_ippicvsPolarToCart_32f", referenced from:
      cv::polarToCart(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, bool) in libopencv_core.a(mathfuncs.cpp.o)
    "_ippicvsPolarToCart_64f", referenced from:
      cv::polarToCart(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, bool) in libopencv_core.a(mathfuncs.cpp.o)
    "_ippicvsPowx_32f_A21", referenced from:
      cv::pow(cv::_InputArray const&, double, cv::_OutputArray const&) in libopencv_core.a(mathfuncs.cpp.o)
    "_ippicvsPowx_64f_A50", referenced from:
      cv::pow(cv::_InputArray const&, double, cv::_OutputArray const&) in libopencv_core.a(mathfuncs.cpp.o)
    "_ippicvsSortAscend_8u_I", referenced from:
      void cv::sort_<unsigned char>(cv::Mat const&, cv::Mat&, int) in libopencv_core.a(matrix.cpp.o)
      void cv::sort_<signed char>(cv::Mat const&, cv::Mat&, int) in libopencv_core.a(matrix.cpp.o)
      void cv::sort_<unsigned short>(cv::Mat const&, cv::Mat&, int) in libopencv_core.a(matrix.cpp.o)
      void cv::sort_<short>(cv::Mat const&, cv::Mat&, int) in libopencv_core.a(matrix.cpp.o)
      void cv::sort_<int>(cv::Mat const&, cv::Mat&, int) in libopencv_core.a(matrix.cpp.o)
      void cv::sort_<float>(cv::Mat const&, cv::Mat&, int) in libopencv_core.a(matrix.cpp.o)
      void cv::sort_<double>(cv::Mat const&, cv::Mat&, int) in libopencv_core.a(matrix.cpp.o)
      ...
    "_ippicvsSortDescend_8u_I", referenced from:
      void cv::sort_<unsigned char>(cv::Mat const&, cv::Mat&, int) in libopencv_core.a(matrix.cpp.o)
      void cv::sort_<signed char>(cv::Mat const&, cv::Mat&, int) in libopencv_core.a(matrix.cpp.o)
      void cv::sort_<unsigned short>(cv::Mat const&, cv::Mat&, int) in libopencv_core.a(matrix.cpp.o)
      void cv::sort_<short>(cv::Mat const&, cv::Mat&, int) in libopencv_core.a(matrix.cpp.o)
      void cv::sort_<int>(cv::Mat const&, cv::Mat&, int) in libopencv_core.a(matrix.cpp.o)
      void cv::sort_<float>(cv::Mat const&, cv::Mat&, int) in libopencv_core.a(matrix.cpp.o)
      void cv::sort_<double>(cv::Mat const&, cv::Mat&, int) in libopencv_core.a(matrix.cpp.o)
      ...
    "_objc_enumerationMutation", referenced from:
      _cvDestroyAllWindows in libopencv_highgui.a(window_cocoa.mm.o)
      _cvShowImage in libopencv_highgui.a(window_cocoa.mm.o)
      _cvGetWindowName in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVWindow cvSendMouseEvent:type:flags:] in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVView setFrameSize:] in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVView drawRect:] in libopencv_highgui.a(window_cocoa.mm.o)
    "_objc_getProperty", referenced from:
      -[CVWindow sliders] in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVView image] in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVSlider slider] in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVSlider name] in libopencv_highgui.a(window_cocoa.mm.o)
    "_objc_msgSend", referenced from:
      _cvInitSystem in libopencv_highgui.a(window_cocoa.mm.o)
      _cvDestroyWindow in libopencv_highgui.a(window_cocoa.mm.o)
      _cvDestroyAllWindows in libopencv_highgui.a(window_cocoa.mm.o)
      _cvShowImage in libopencv_highgui.a(window_cocoa.mm.o)
      _cvNamedWindow in libopencv_highgui.a(window_cocoa.mm.o)
      _cvResizeWindow in libopencv_highgui.a(window_cocoa.mm.o)
      _cvMoveWindow in libopencv_highgui.a(window_cocoa.mm.o)
      ...
    "_objc_msgSendSuper2", referenced from:
      -[CVWindow keyDown:] in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVWindow contentView] in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVView init] in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVView setFrameSize:] in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVView drawRect:] in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVSlider init] in libopencv_highgui.a(window_cocoa.mm.o)
    "_objc_msgSend_stret", referenced from:
      _cvShowImage in libopencv_highgui.a(window_cocoa.mm.o)
      _cvNamedWindow in libopencv_highgui.a(window_cocoa.mm.o)
      _cvResizeWindow in libopencv_highgui.a(window_cocoa.mm.o)
      _cvMoveWindow in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVWindow cvSendMouseEvent:type:flags:] in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVWindow createSliderWithName:maxValue:value:callback:] in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVView setFrameSize:] in libopencv_highgui.a(window_cocoa.mm.o)
      ...
    "_objc_setProperty_atomic", referenced from:
      -[CVWindow setSliders:] in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVView setImage:] in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVSlider setSlider:] in libopencv_highgui.a(window_cocoa.mm.o)
      -[CVSlider setName:] in libopencv_highgui.a(window_cocoa.mm.o)
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [SURFFeatures] Error 1

0 个答案:

没有答案