Crosscompiling VisualGDB/C++ Cubietruck => Linkererror

290 Views Asked by At

i am trying to get an opencv c++ program, which runs on my laptop, on my hardware - furthermore i should mention, that i am new to embedded programming. May someone can help me, because i got problems while cross-compiling with VisualGDB. I am using following board: Cubieboard 3 (Cubietruck- Dual-Core A20)

The toolchain is stored locally - so not on the board itself. All libraries are included and detected in Visual Studio --> take a look at the Screenshot:

The "opencv_world320d.lib" - Library includes all the needed sub libraries - i found that here

The C++ code itself:

#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;
}

When I try to build the linker fails with following message:

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

Maybe someone had the same problems - i really searched a lot, but i wasn't able to find similar issues.

1

There are 1 best solutions below

4
On

You have only told the toolchain where to look when searching for libraries ("Library directory"). You have not told it which libraries to link to... So it not being able to find any symbols from those missing libraries is completely unsurprising.

So, in addition to the library search directory/ies, you also need to populate the "Library names" field with the names of any libraries whose symbols you are referencing - in this case, at least opencv. That way, the linker can link to those libraries and therefore resolve those symbols.

Edit as per now-completely-different question

Based on this thread: Telling gcc directly to link a library statically It looks like you should move any static libraries into the "Additional linker" flags, as the "Library names" generates -l switches (not -l:), which are for dynamic libraries, but you are trying to link a static library.