Reputation: 1581
I already linked to gdi32.lib. In desperation, I also linked to two different versions of gdi32.lib, as well as gdiplus.lib, and included all the gdi headers I could find, to no avail. However, this problem began before the extra links, so I think I can safely assume my problem isn't collisions between libraries or any sort of interference like that.
Inclusions/definitions:
#define WINVER 0x0500
#define _WIN32_WINNT 0x0500
#include <iostream>
#include <process.h>
#include <windows.h>
#include <winuser.h>
#include <gdiplus.h>
#include "UVMap.h"
Related code:
case WM_PAINT:{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HDC hdcMemory = CreateCompatibleDC(hdc);
BITMAP bmp = screen.getBitmap(hdcMemory);
BitBlt(hdc,0,0,w,h,hdcMemory,0,0,SRCCOPY);
EndPaint(hwnd,&ps);
DeleteDC(hdc);
}break;
Every result I found when searching for this problem claimed that you just had to link to gdi32. Here are the links I added:
Edit: the errors appear like this:
.../Testing.cpp:50: undefined reference to `CreateCompatibleDC@4'
.../Testing.cpp:52: undefined reference to `BitBlt@36'
Like that? I did the linking in Eclipse, via Project > Properties > Path Variables. There are no entries under the Linked Resources tab, nor does it appear editable.
Upvotes: 4
Views: 8805
Reputation: 87
I have the same problem, but i build using sublime text.
So i came across with Sublime build system, i copy & paste the .json build from c++ .sublime-packages then i make new build system,
then i add -lgdi32 in the end of the line.
and if i press F7 or Ctrl + B and works fine!
The code of the json looks like this!
{
"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" -lgdi32",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c++",
"variants":
[
{
"name": "Run",
"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" -lgdi32 && \"${file_path}/${file_base_name}\""
}
]
}
Upvotes: 4
Reputation: 23550
If you are getting the error undefined reference
to functions defined in gdi32 but are already linking gdi32 then try moving gdi32 to the end of your linking commands.
Upvotes: 1
Reputation: 38228
You need to link to coredll.lib for CreateCompatibleDC
.
You need to link to for Gdi32.lib for BitBlt
.
For reference, when you get a link error involving a Windows function, just google the function and go to the MSDN documentation for that function (I've linked to the two pages for these two specific functions), and then scroll down to the Requirements section and make sure you're linking to the specified library.
Upvotes: 5