Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I link to a library with Code::Blocks?

C++ GUI Tutorial: undefined reference to TextOut

I have the same problem, but I'm new to programming and Code::Blocks, and I want to use the GDI32 library. How can I install it? I'm very confused because I can use the windows.h header, but some functions like TextOut aren't available.

like image 201
optimusfrenk Avatar asked May 02 '11 21:05

optimusfrenk


People also ask

How do I run multiple programs in Code::Blocks?

From IDE: Use Tools -> Configure tools -> User-defined tools to create a new tool, for example call it exe_tester as shown in example image below. (this name is arbitrary) Note: The exe must have already been built. Use the ... navigate button to navigate to the actual location of the exe, and select the .exe (eg.


1 Answers

The gdi32 library is already installed on your computer, few programs will run without it. Your compiler will (if installed properly) normally come with an import library, which is what the linker uses to make a binding between your program and the file in the system. (In the unlikely case that your compiler does not come with import libraries for the system libs, you will need to download the Microsoft Windows Platform SDK.)

To link with gdi32:

enter image description here

This will reliably work with MinGW-gcc for all system libraries (it should work if you use any other compiler too, but I can't talk about things I've not tried). You can also write the library's full name, but writing libgdi32.a has no advantage over gdi32 other than being more type work.
If it does not work for some reason, you may have to provide a different name (for example the library is named gdi32.lib for MSVC).

For libraries in some odd locations or project subfolders, you will need to provide a proper pathname (click on the "..." button for a file select dialog).

like image 200
Damon Avatar answered Oct 16 '22 02:10

Damon