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

后端 未结 2 1234
终归单人心
终归单人心 2020-11-22 06:04

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

相关标签:
2条回答
  • 2020-11-22 06:24

    At a guess, you used Code::Blocks to create a Console Application project. Such a project does not link in the GDI stuff, because console applications are generally not intended to do graphics, and TextOut is a graphics function. If you want to use the features of the GDI, you should create a Win32 Gui Project, which will be set up to link in the GDI for you.

    0 讨论(0)
  • 2020-11-22 06:35

    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).

    0 讨论(0)
提交回复
热议问题