1

I am learning how to make Windows applications in C, and am trying to set individual pixels using SetPixel(HDC hDC, int x, int y, COLORREF crColor).

I have never had a compile error until I added that line into it. I do have windows.h included of course. I have searched around for an answer, and I never found anything.

It gives the error " undefined reference to _imp__SetPixel@16' "

To compile, I am using the command " gcc -g -Wall -o $(EXENAME) $(SRC) ". No fancy IDE. If someone could tell me why is says imp_ and the @16 part, please do as well. I have never seen that before.

EDIT: I have found what the _imp means at this site.

Znapi
  • 395
  • 1
  • 3
  • 11

2 Answers2

5

Besides including the header file, I believe you also need to link to the library libgdi32.a or gdi32.lib.

As pointed out below, _imp__SetPixel@16 is a mangled name for the function SetPixel() you're calling.

downhillFromHere
  • 1,967
  • 11
  • 11
1

from the MSDN website, you should be including #include <Windows.h> in the same area as you other headers file (like stdio.h, stdlib.h, string.h, etc...).

If that doesn't work, you might want to try compiling with linker options that link to the right libraries listed on that same website (Gdi32.lib).

Another thing to double check is that Gdi32.dll is in either

A. In your execution directory or

B. In your system32 / sysWOW64 folder on windows

I recommend A because if you ever try to send your program to somebody, the .dll file will be with your executable (not all computers have all the same .dll files).

Cheers,

Jensen.

Ryan Jensen
  • 207
  • 1
  • 9