如何使用 Code::Blocks 链接到库?

2021-12-01 00:00:00 winapi c++ codeblocks

C++ GUI 教程:对 TextOut 的未定义引用

我有同样的问题,但我是编程和 Code::Blocks 的新手,我想使用 GDI32 库.我该如何安装它?我很困惑,因为我可以使用 windows.h 标头,但是诸如 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.

推荐答案

gdi32 库已经安装在您的计算机上,没有它,很少有程序可以运行.您的编译器(如果安装正确)通常会附带一个导入库,链接器使用它来在您的程序和系统中的文件之间进行绑定.(万一您的编译器没有为系统库提供导入库,您将需要下载 Microsoft Windows 平台 SDK.)

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

与 gdi32 链接:

To link with gdi32:

这将可靠地与 MinGW-gcc 一起用于所有系统库(如果您也使用任何其他编译器,它应该可以,但我不能谈论我没有尝试过的东西).你也可以写出库的全名,但是写libgdi32.agdi32 相比没有任何优势,除了更多类型的工作.
如果由于某种原因它不起作用,您可能需要提供一个不同的名称(例如,对于 MSVC,该库被命名为 gdi32.lib).

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

相关文章