Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Friday, July 30, 2010

mingw and gcc

If you want to use API calls you need to do two things:

- include the right header file so C/C++ knows the function prototypes for the calls, and the types and structures that they use as parameters
- link in the right library file (.a files in .\lib), which I'm guessing contains the object code that actually implements the calls. There appears to be a 1:1 .a file/.dll file correspondence.

Eg to use GetDeviceCaps in gdi32.dll, you need to include wingdi.h and link to libgdi32.a by adding -lgdi32 to your gcc invocation.

If you're just calling stuff from user32.dll (definitions in windows.h) you don't seem to need to say -luser32. Looking into this further with the very helpful -v compiler switch, I see that gcc links to the following libraries by default

-lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt

Indeed I see that it does this for the simplest hello.c program, even without windows.h being included. That's not a complaint, I just want to know how it is.

Followers

Blog Archive