Home >Backend Development >C++ >How to Resolve Undefined Reference Errors When Linking to the GDI32 Library in Code::Blocks?

How to Resolve Undefined Reference Errors When Linking to the GDI32 Library in Code::Blocks?

Linda Hamilton
Linda HamiltonOriginal
2024-12-15 02:40:15871browse

How to Resolve Undefined Reference Errors When Linking to the GDI32 Library in Code::Blocks?

Linking to the GDI32 Library in Code::Blocks: Resolved

In Code::Blocks, linking to external libraries can be a stumbling block, especially for beginners. A common issue is the undefined reference error when using GDI32 library functions like TextOut, despite having the windows.h header included.

The solution lies in linking your program with the GDI32 import library. This import library is a precompiled file that contains the necessary information for the linker to create references to functions and data in the GDI32 system DLL.

To link with GDI32 in Code::Blocks:

  1. Click on the "Project" menu and select "Build Options".
  2. In the "Linker settings" tab, locate the "Link libraries" section.
  3. Click on the " " button and add "gdi32".
  4. If your compiler is MinGW-gcc, you can also enter "libgdi32.a" instead of just "gdi32".
  5. Click "OK" to save the changes.

Recompile your program and the undefined reference error for TextOut should be gone. This process applies to other system libraries as well. It is also possible to link with libraries located in non-standard locations by providing the full pathname in the "Link libraries" section.

The above is the detailed content of How to Resolve Undefined Reference Errors When Linking to the GDI32 Library in Code::Blocks?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn