0

I am very new to c++ and I cant seem to get this code to work:

#include <iostream>
#include <windows.h>
using namespace std;

int main() {
  HBITMAP hbm = CreateBitmap(100, 100, 1, 24, NULL);
  return 0;
}

The console outputs: "undefined reference to `__imp_CreateBitmap'" whenever I try to compile it. Am I forgetting a #include statement or is it something else?

Dusty Berkley
  • 32
  • 1
  • 6
  • You need add *gdi32.lib* to linker input. And this error not at compile but at link time – RbMm Jan 05 '22 at 02:49
  • 1
    1. Read the documentation for [`CreateBitmap`](https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createbitmap). 2. Scroll down to the Requirements section and find the Library entry. It tells you which library the API requires linking against. Fyi, this is near-universally true for *all* windows sdk apis. – WhozCraig Jan 05 '22 at 02:56
  • 1
    Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?: Failure to link against appropriate libraries/object files or compile implementation files](https://stackoverflow.com/a/12574400): "In Windows programming, the tell-tale sign that you did not link a necessary library is that the name of the unresolved symbol begins with __imp_. Look up the name of the function in the documentation, and it should say which library you need to use. MSDN puts the information in a box at the bottom of each function in a section called "Library"." – Raymond Chen Jan 05 '22 at 05:16
  • That is correct, I did forget to include the dll file. Thank you for helping – Dusty Berkley Jan 05 '22 at 20:25

0 Answers0