Eclipse CDT undefined reference(通过MYSYS2下载的包)

Eclipse CDT undefined reference (package that was downloaded via MYSYS2)

所以我在大学基本上只用 Java 编码,这次 我想用 C++ 开始我的新项目,并想保留我一直使用的 Eclipse IDE。我需要 openCV 和 Tesseract 包(导入)。我已经用谷歌搜索和研究了很长时间,我似乎做得对吗?但也许你们中的一些人可以告诉我其他情况。

我做了什么:

  1. 已下载 Eclipse CDT
  2. 已下载 MYSYS2
  3. 遵循此说明(MinGW 编译器)

    1. Open MSYS2 shell from start menu
    2. Run pacman -Sy pacman to update the package database
    3. Re-open the shell, run pacman -Syu to update the package database and core system packages
    4. Re-open the shell, run pacman -Su to update the rest
    5. (Reference)
      • For 64 bits, run pacman -S mingw-w64-x86_64-toolchain
    6. Select which package to install, default is all
    7. You may also need make, run pacman -S make
  4. 安装了我需要的libraries/tools

    OpenCV

    pacman -S mingw64/mingw-w64-x86_64-opencv

    超正方体

    pacman -S mingw64/mingw-w64-x86_64-tesseract-ocr

  5. 将MinGW加入PATH(系统环境变量)->重启电脑

  6. 开始一个新的 Eclipse 项目-> C++ -> 选择 MinGW GCC 作为工具链

  7. 基本 Hello World -> 工作正常

  8. 基本 OpenCV 示例 -> 不起作用

似乎正确解决了夹杂物。

#include <opencv2/core/core.hpp>

#include <opencv2/highgui/highgui.hpp>

那里没有错误。

完整代码:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
    if( argc != 2)
    {
     cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
     return -1;
    }

    Mat image;
    image = imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file

    if(! image.data )                              // Check for invalid input
    {
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;
    }

    namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
    imshow( "Display window", image );                   // Show our image inside it.

    waitKey(0);                                          // Wait for a keystroke in the window
    return 0;
}

Eclipse 所说的内容:

16:54:43 **** Incremental Build of configuration Debug for project hello ****
Info: Internal Builder is used for build
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o "src\hello.o" "..\src\hello.cpp" 
g++ -o hello.exe "src\hello.o" 
src\hello.o: In function `main':
C:\Users\Vaio\Desktop\EclipseProjekte\hello\Debug/../src/hello.cpp:17: undefined reference to `cv::imread(cv::String const&, int)'
C:\Users\Vaio\Desktop\EclipseProjekte\hello\Debug/../src/hello.cpp:25: undefined reference to `cv::namedWindow(cv::String const&, int)'
C:\Users\Vaio\Desktop\EclipseProjekte\hello\Debug/../src/hello.cpp:26: undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
C:\Users\Vaio\Desktop\EclipseProjekte\hello\Debug/../src/hello.cpp:28: undefined reference to `cv::waitKey(int)'
src\hello.o: In function `cv::String::String(char const*)':
C:/msys64/mingw64/include/opencv2/core/cvstd.hpp:602: undefined reference to `cv::String::allocate(unsigned long long)'
src\hello.o: In function `cv::String::~String()':
C:/msys64/mingw64/include/opencv2/core/cvstd.hpp:648: undefined reference to `cv::String::deallocate()'
src\hello.o: In function `cv::Mat::~Mat()':
C:/msys64/mingw64/include/opencv2/core/mat.inl.hpp:692: undefined reference to `cv::fastFree(void*)'
src\hello.o: In function `cv::Mat::release()':
C:/msys64/mingw64/include/opencv2/core/mat.inl.hpp:804: undefined reference to `cv::Mat::deallocate()'
src\hello.o: In function `cv::Mat::operator=(cv::Mat&&)':
C:/msys64/mingw64/include/opencv2/core/mat.inl.hpp:1371: undefined reference to `cv::fastFree(void*)'
collect2.exe: error: ld returned 1 exit status

16:54:46 Build Finished (took 2s.908ms)

找不到图书馆???? 如果它不像 iostream

那样连接库,那么通过 MSYS2 下载它有什么意义

是否需要将所有库对象添加到链接器设置中C/C++ Build -> Settings -> Tool Settings -> GCC C++ Linker -> Libraries

好的,所以我猜它是 obv,但对于那些有同样错误的人,MSYS2 只是添加了所有 opencv 和 tesseract 文件。

如果您想使用它们,您需要将其指定给链接器。

文件名:libopencv_core.dll.a

需要排除开头的lib以及.dll和.a

link呃:opencv_core

所有库都可以在mingw路径下找到:(C:\msys64\mingw64\lib)

最后你link它用-lopencv_core

或通过 Eclipse GUI C/C++ 构建 -> 设置 -> 工具设置 -> GCC C++ 链接器 -> 库 -> 添加库 -> opencv_core