我正在尝试设置 vs code 来与 gtk 一起使用,我正在用 c 进行编程,我按照如何使用 msys64 安装 gtk 的说明进行操作,然后我尝试运行一个 hello world 示例他们的页面,但 VS Code 似乎在查找 gtk 头文件时遇到问题。
错误:
gtk/gtk.h: No such file or directory
我也相信当我运行命令时 gtk 已安装
kg-config --cflags --libs gtk4
输出: -IC:/msys64/mingw64/bin/../include/gtk-4.0 -IC:/msys64/mingw64/bin/../include/pango-1.0 -IC:/msys64/mingw64/bin /../include -IC:/msys64/mingw64/bin/../include/glib-2.0 -IC:/msys64/mingw64/bin/../lib/glib-2.0/include -IC:/msys64/mingw64 /bin/../include/harfbuzz -IC:/msys64/mingw64/bin/../include/freetype2 -IC:/msys64/mingw64/bin/../include/libpng16 -IC:/msys64/mingw64/bin /../include/fribidi -IC:/msys64/mingw64/bin/../include/cairo -IC:/msys64/mingw64/bin/../include/lzo -IC:/msys64/mingw64/bin/. ./include/pixman-1 -IC:/msys64/mingw64/bin/../include/gdk-pixbuf-2.0 -IC:/msys64/mingw64/bin/../include/graphene-1.0 -IC:/msys64 /mingw64/bin/../lib/graphene-1.0/include -mfpmath=sse -msse -msse2 -LC:/msys64/mingw64/bin/../lib -lgtk-4 -lpangowin32-1.0 -lpangocairo-1.0 - lpango-1.0 -lharfbuzz -lgdk_pixbuf-2.0 -lcairo-gobject -lcairo -lgraphene-1.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl
c_cpp_属性:
"configurations": [
{
"name": "Gtk_dev",
"includePath": [
"${workspaceFolder}/**",
"C:/msys64/mingw64/include/**",
"C:/msys64/mingw64/lib/gtk-4.0",
"C:/msys64/mingw64/lib/glib-2.0/include",
"C:/msys64/mingw64/lib/graphene-1.0/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/msys64/mingw64/bin/gcc.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "gcc-x64",
"compilerArgs": [],
"browse": {
"limitSymbolsToIncludedHeaders": false,
"path": []
}
}
],
"version": 4
}
几分钟前我也遇到了同样的问题。按照 gtk REAME 在 github 上推荐的步骤构建您自己的库。
对于 gvsBuild 我发现这比使用 msys64 更好
mkdir C:\gtk-build\github
cd C:\gtk-build\github
git clone https://github.com/wingtk/gvsbuild.git
cd C:\gtk-build\github\gvsbuild
python -m venv .venv
.\.venv\Scripts\activate.ps1
pip install .
然后运行此命令根据您的喜好构建版本 3 或 4 的 gtk。我做了大概五次才成功。原因?我不知道。
gvsbuild build gtk3
使用 Windows 中的 GUI 手动更新环境变量
将“包含”文件的路径添加到 VSCode
C:\gtk-build\gtk\x64\release\**
这将确保 gtk 的所有包含文件都能被 VsCode 识别。