【问题标题】:Crosscompiling VisualGDB/C++ Cubietruck => Linkererror交叉编译 VisualGDB/C++ Cubietruck => Linkererror
【发布时间】:2018-01-10 00:28:24
【问题描述】:

我正在尝试获得一个 opencv c++ 程序,该程序在我的笔记本电脑和我的硬件上运行 - 此外,我应该提到,我是嵌入式编程的新手。 可能有人可以帮助我,因为我在使用 VisualGDB 进行交叉编译时遇到了问题。我正在使用以下板:Cubieboard 3 (Cubietruck- Dual-Core A20)

工具链存储在本地 - 因此不在电路板上。 所有库都包含在 Visual Studio 中并被检测到 --> 看一下屏幕截图:

opencv_world320d.lib” - 库包含所有需要的子库 - 我发现 here

C++ 代码本身:

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

using namespace cv;
using namespace std;

int main(int argc, const char** argv)
{
    Mat img(500, 1000, CV_8UC3, Scalar(0, 0, 100)); //create an image ( 3 channels, 8 bit image depth, 500 high, 1000 wide, (0, 0, 100) assigned for Blue, Green and Red plane respectively. )

    if (img.empty()) //check whether the image is loaded or not
    {
        cout << "Error : Image cannot be loaded..!!" << endl;
        //system("pause"); //wait for a key press
        return -1;
    }

    namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
    imshow("MyWindow", img); //display the image which is stored in the 'img' in the "MyWindow" window

    waitKey(0);  //wait infinite time for a keypress

    destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"

    return 0;
}

当我尝试构建链接器失败并显示以下消息:

1>------ Erstellen gestartet: Projekt: LinuxProject2, Konfiguration: Debug VisualGDB ------
1>  Linking VisualGDB/Debug/LinuxProject2...
1>  VisualGDB/Debug/LinuxProject2.o: In function `cv::String::String(char const*)':
1>C:\OpenCV-3.2.0\opencv\build\include\opencv2\core\cvstd.hpp(622): error : undefined reference to `cv::String::allocate(unsigned int)'
1>  VisualGDB/Debug/LinuxProject2.o: In function `cv::String::~String()':
1>C:\OpenCV-3.2.0\opencv\build\include\opencv2\core\cvstd.hpp(664): error : undefined reference to `cv::String::deallocate()'
1>  VisualGDB/Debug/LinuxProject2.o: In function `cv::Mat::Mat(int, int, int, cv::Scalar_<double> const&)':
1>C:\OpenCV-3.2.0\opencv\build\include\opencv2\core\mat.inl.hpp(352): error : undefined reference to `cv::Mat::operator=(cv::Scalar_<double> const&)'
1>  VisualGDB/Debug/LinuxProject2.o: In function `cv::Mat::~Mat()':
1>C:\OpenCV-3.2.0\opencv\build\include\opencv2\core\mat.inl.hpp(592): error : undefined reference to `cv::fastFree(void*)'
1>  VisualGDB/Debug/LinuxProject2.o: In function `cv::Mat::create(int, int, int)':
1>C:\OpenCV-3.2.0\opencv\build\include\opencv2\core\mat.inl.hpp(684): error : undefined reference to `cv::Mat::create(int, int const*, int)'
1>  VisualGDB/Debug/LinuxProject2.o: In function `cv::Mat::release()':
1>C:\OpenCV-3.2.0\opencv\build\include\opencv2\core\mat.inl.hpp(704): error : undefined reference to `cv::Mat::deallocate()'
1>  VisualGDB/Debug/LinuxProject2.o: In function `main':
1>D:\Softwareentwicklung\Projects\LinuxProject2\LinuxProject2.cpp(18): error : undefined reference to `cv::namedWindow(cv::String const&, int)'
1>D:\Softwareentwicklung\Projects\LinuxProject2\LinuxProject2.cpp(19): error : undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
1>D:\Softwareentwicklung\Projects\LinuxProject2\LinuxProject2.cpp(21): error : undefined reference to `cv::waitKey(int)'
1>D:\Softwareentwicklung\Projects\LinuxProject2\LinuxProject2.cpp(23): error : undefined reference to `cv::destroyWindow(cv::String const&)'
1>collect2.exe : error : ld returned 1 exit status

也许有人有同样的问题 - 我确实搜索了很多,但我无法找到类似的问题。

【问题讨论】:

标签: c++ linux opencv cross-compiling visualgdb


【解决方案1】:

您只告诉工具链在搜索库(“库目录”)时要查找的位置。您还没有告诉它要链接到哪些库...所以它无法从那些丢失的库中找到任何符号完全不足为奇。

因此,除了库搜索目录之外,您还需要使用您要引用其符号的任何库的名称填充“库名称”字段 - 在这种情况下,至少是 opencv。这样,链接器就可以链接到这些库,从而解析这些符号。

根据现在完全不同的问题进行编辑

基于此线程: Telling gcc directly to link a library statically 看起来您应该将任何静态库移动到“附加链接器”标志中,因为“库名称”会生成用于动态库的 -l 开关(不是 -l:),但您正在尝试链接静态库.

【讨论】:

  • 我以前试过这个——我把所有东西都链接到了现有的、正在运行的程序中。但是链接器找不到该库文件。我更新了屏幕截图和输出。
  • 太好了,现在你已经改变了我下面的问题。 /叹息
  • 我找到了这个链接:stackoverflow.com/questions/34867289/… 这里提到应该只有一个库链接。我现在把它放到“附加链接器”中:C:\OpenCV-3.2.0\opencv\build\x64\vc14\lib\opencv_world320d.lib 但是我得到了很多“未定义的引用”。
  • 请使用此类更新编辑您的问题,而不是在 cmets 中发布它们。评论被认为是短暂的,随时可能消失,此外,留下一个过时的问题并期望读者通过 cmets 来获取最新状态是没有用的。
猜你喜欢
  • 1970-01-01
  • 2016-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-28
  • 2020-04-27
  • 2019-07-06
  • 2010-10-07
相关资源
最近更新 更多