如何使用 Code::Blocks 链接到库?
我有同样的问题,但我是编程和 Code::Blocks 的新手,并且我想使用 GDI32 库。我该如何安装它?我很困惑,因为我可以使用 windows.h 标头,但某些功能(如 TextOut
)不可用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据猜测,您使用 Code::Blocks 创建了一个控制台应用程序项目。这样的项目不会链接 GDI 内容,因为控制台应用程序通常不打算执行图形操作,而
TextOut
是一个图形函数。如果您想使用 GDI 的功能,您应该创建一个 Win32 Gui 项目,它将被设置为链接到 GDI 中。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.gdi32 库已经安装在您的计算机上,没有它,很少有程序可以运行。您的编译器(如果安装正确)通常会附带一个导入库,链接器用它来在您的程序和系统中的文件之间进行绑定。 (在不太可能的情况下,您的编译器没有附带系统库的导入库,您将需要下载 Microsoft Windows Platform SDK。)
要与 gdi32 链接:
这将可靠地与 MinGW-gcc 一起用于所有系统库(如果您也使用任何其他编译器,它应该可以,但我不能谈论我没有做过的事情尝试过)。您还可以编写库的全名,但编写
libgdi32.a
与gdi32
相比,除了更多的类型工作外没有任何优势。如果由于某种原因它无法工作,您可能必须提供不同的名称(例如,MSVC 的库名为
gdi32.lib
)。对于某些奇怪位置或项目子文件夹中的库,您需要提供正确的路径名(单击文件选择对话框的“...”按钮)。
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:
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 overgdi32
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).
您可以使用项目 win32 gui api 创建新项目,它具有默认添加库 -lgdi32 -luser32 -lkernel32 -lcomctl32 -mwindows 或在项目中添加库 -mwindows ,它适用于我。
You can create new with project win32 gui api it has default add library -lgdi32 -luser32 -lkernel32 -lcomctl32 -mwindows or add library -mwindows in your project, it worked for me.