You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Code::Blocks中GTK+2编译报错:undefined reference to `gdk_cairo_create`

Fixing "undefined reference to 'gdk_cairo_create'" in Code::Blocks with GTK+2

Hey there, let's get this linking issue sorted out—you're already halfway there since you noticed the missing libraries in the working project! Here's how to fix it step by step:

First, we need to make sure your problematic project includes the libraries that the working one has:

  • Right-click your project in Code::Blocks and select Build Options
  • Switch to the Linker settings tab
  • Under Link libraries, click the Add button
    • Browse to C:\Program Files (x86)\CodeBlocks\gtk\lib and select gdk-win32-2.0.lib
    • Repeat to add pango-1.0.lib
  • Alternatively, you can add these directly to Other linker options with -lgdk-win32-2.0 and -lpango-1.0 (just make sure they're in the right order—more on that next!)

2. Adjust Linker Order (Critical for MinGW!)

MinGW's linker is picky about library order—libraries that depend on other libraries need to come BEFORE the libraries they depend on. For GTK+2 projects, the correct order usually looks like this:

-lgtk-win32-2.0 -lgdk-win32-2.0 -lpangocairo-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lcairo

To adjust this in Code::Blocks:

  • In the Link libraries list, drag and drop the entries to match the order above
  • If you're using Other linker options, just retype the flags in that exact sequence

3. Verify the Fix

Rebuild your project and check the build log again—you should see the full set of libraries in the correct order in the mingw32-g++.exe link command. If the undefined reference error is gone, you're good to go!

Quick Why This Happened

After your system reinstall, your project's linker configuration probably didn't carry over the full set of GTK+2 dependencies. Since gdk_cairo_create() is part of the GDK library, linking against gdk-win32-2.0.lib is non-negotiable, and the order ensures the linker finds all the required symbols properly.

内容的提问来源于stack exchange,提问作者Eric Wajnberg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:55:10