Screen Video Capture / opencv/Windows API linkage issues

Trying to get some data from screenKeep gettings linking errors.
Honestly, was trying to get any help in google, two hours gave me nothing. Please advise. Using QT/OpenCV/Windows 10

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio.hpp>
#include <Windows.h>
#include <iostream>

using namespace std;
using namespace cv;

class hwnd2Mat
    hwnd2Mat(HWND hwindow, float scale = 1);
    virtual ~hwnd2Mat();
    virtual void read();
    Mat image;

    HWND hwnd;
    HDC hwindowDC, hwindowCompatibleDC;
    int height, width, srcheight, srcwidth;
    HBITMAP hbwindow;

hwnd2Mat::hwnd2Mat(HWND hwindow, float scale)
    hwnd = hwindow;
    hwindowDC = GetDC(hwnd);
    hwindowCompatibleDC = CreateCompatibleDC(hwindowDC);
    SetStretchBltMode(hwindowCompatibleDC, COLORONCOLOR);

    RECT windowsize;    // get the height and width of the screen
    GetClientRect(hwnd, &windowsize);

    srcheight = windowsize.bottom;
    srcwidth = windowsize.right;
    height = (int)(windowsize.bottom * scale);
    width = (int)(windowsize.right * scale);

    image.create(height, width, CV_8UC4);

    // create a bitmap
    hbwindow = CreateCompatibleBitmap(hwindowDC, width, height);
    bi.biSize = sizeof(BITMAPINFOHEADER);    //
    bi.biWidth = width;
    bi.biHeight = -height;  //this is the line that makes it draw upside down or not
    bi.biPlanes = 1;
    bi.biBitCount = 32;
    bi.biCompression = BI_RGB;
    bi.biSizeImage = 0;
    bi.biXPelsPerMeter = 0;
    bi.biYPelsPerMeter = 0;
    bi.biClrUsed = 0;
    bi.biClrImportant = 0;

    // use the previously created device context with the bitmap
    SelectObject(hwindowCompatibleDC, hbwindow);

void hwnd2Mat::read()
    // copy from the window device context to the bitmap device context
    StretchBlt(hwindowCompatibleDC, 0, 0, width, height, hwindowDC, 0, 0, srcwidth, srcheight, SRCCOPY); //change SRCCOPY to NOTSRCCOPY for wacky colors !
    GetDIBits(hwindowCompatibleDC, hbwindow, 0, height,, (BITMAPINFO*)&bi, DIB_RGB_COLORS);  //copy from hwindowCompatibleDC to hbwindow

    // avoid memory leak
    ReleaseDC(hwnd, hwindowDC);

int main()
    Mat ui(40, 400, CV_8UC3, Scalar(0, 130, 0));
    putText(ui, "Press Esc to stop capturing", Point(30,30), FONT_HERSHEY_COMPLEX, 0.7,
        Scalar(0, 0, 255), 1);
    Mat bgrImg;
    hwnd2Mat capDesktop(GetDesktopWindow());

    VideoWriter writer;
    int codec = VideoWriter::fourcc('X', 'V', 'I', 'D');
    double fps = 10.0;
    string filename = "./desktop_capture.avi";, codec, fps, capDesktop.image.size(), true);
    // check if we succeeded
    if (!writer.isOpened()) {
        cerr << "Could not open the output video file for write\n";
        return -1;

    while ( true )
        cvtColor(capDesktop.image, bgrImg, COLOR_BGRA2BGR);
        writer << bgrImg;
        imshow("desktop capture", ui);
        int key = waitKey(5);

        if (key == 27)
error: release/main.o:main.cpp:(.text+0x59): undefined reference to `__imp_StretchBlt'
error: release/main.o:main.cpp:(.text+0x91): undefined reference to ` __imp_GetDIBits'
error: release/main.o:main.cpp:(.text+0xbb): undefined reference to `__imp_DeleteObject'
error: release/main.o:main.cpp:(.text+0xc5): undefined reference to ` __imp_DeleteDC'
error: release/main.o:main.cpp:(.text+0x1bc): undefined reference to `__imp_DeleteObject'
error: release/main.o:main.cpp:(.text+0x1c7): undefined reference to ` __imp_DeleteDC'
error: release/main.o:main.cpp:(.text+0x246): undefined reference to `__imp_CreateCompatibleDC'
error: release/main.o:main.cpp:(.text+0x259): undefined reference to ` __imp_SetStretchBltMode'
error: release/main.o:main.cpp:(.text+0x2db): undefined reference to `__imp_CreateCompatibleBitmap'
error: release/main.o:main.cpp:(.text+0x34f): undefined reference to ` __imp_SelectObject'

which compiler do you use ?

all you need is gdi32 (-lgdi32 for mingw, gdi32.lib for VS (i think))

im not entirely sure, but i think its MinGW for QT

How can i activate gdi32?

again, just add -lgdi32 to your linker cmdline

and, just out of curiosity:

g++ --version

reports what ?

it works! thank you mister

One more question please:
I need to output the captured video stream, how can I do it, using current code
Big thanks in adavance

what ? your code is doing that already, no ?