Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add gdi32.lib from command line

Tags:

gcc

linker

I have found an example where gdi32.lib should be linked in some way, but I don't know how to do this from GCC command line. All the examples I've found suggest to do this somewhere in project properties in MS Visual Studio or Eclipse.

bsod.cpp:

#include <windows.h>
int main() {
    HDC dc = CreateCompatibleDC (NULL);
    SetLayout (dc, LAYOUT_RTL);
    ScaleWindowExtEx (dc, -2147483647 - 1, -1, 1, 1, NULL);
}

My GCC compiler is from Ruby Development Kit (seems to be MinGW).

like image 683
Paul Avatar asked Dec 09 '22 15:12

Paul


1 Answers

Just add this to the link command line:

-lgdi32

So that e.g. your link line will look like

gcc -o executable somemain.o -lgdi32

Make sure the library is specified after anything that needs it.


For example, if you have a single C++ source file named myprog.cpp, you would run

g++ -o myprog myprog.cpp -lgdi32

Or seperate the commands

g++ -c myprog.cpp
g++ -o myprog myprog.o -lgdi32

You can add optimization or debug options to the first two commands. The link command doesn't really need anything else.

like image 134
rubenvb Avatar answered Feb 15 '23 23:02

rubenvb