加载中...

M1 Macbook 使用VScode搭建GTK4环境

首先安装M1 Mackbook上的homebrew,然后使用brew install gtk4 安装,但是似乎和Intel上的不太一样,默认会将每个离散得包安装到/opt/homebrew/Cellar/目录下。这简直是天坑。。目前还没有发现简易得办法,不像linux会统一安装到/usr/include,所以得一个一个得将include path配全。

三个json文件配置如下(已经过hello word 测试):

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**",
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
                "/Library/Developer/CommandLineTools/usr/include",
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",
                "/Library/Developer/CommandLineTools/usr/lib/clang/12.0.5/include",
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks",
                "/opt/homebrew/Cellar/gtk4/4.2.1/include/gtk-4.0/",
                "/opt/homebrew/Cellar/glib/2.68.3/include/glib-2.0/",
                "/opt/homebrew/Cellar/glib/2.68.3/include/gio-unix-2.0/",
                "/opt/homebrew/Cellar/glib/2.68.3/lib/glib-2.0/include/",
                "/opt/homebrew/Cellar/pango/1.48.7/include/pango-1.0/",
                "/opt/homebrew/Cellar/harfbuzz/2.8.2/include/harfbuzz/",
                "/opt/homebrew/Cellar/cairo/1.16.0_5/include/cairo/",
                "/opt/homebrew/Cellar/gdk-pixbuf/2.42.6/include/gdk-pixbuf-2.0/",
                "/opt/homebrew/Cellar/atk/2.36.0/include/atk-1.0/",
                "/opt/homebrew/Cellar/graphene/1.10.6/include/graphene-1.0/",
                "/opt/homebrew/Cellar/graphene/1.10.6/lib/graphene-1.0/include/",
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++98",
            "intelliSenseMode": "macos-clang-arm64"
        }
    ],
    "version": 4
}

tasks.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: gcc 生成活动文件",
            "command": "clang++",
            "args": [
                "-g",
                "`pkg-config","--libs","--cflags","gtk4`",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ],
    "version": "2.0.0"
}


launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gcc - 生成和调试活动文件",
            "type": "lldb",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "C/C++: gcc 生成活动文件"
        }
    ]
}

搜索公众号「求密勒实验室」,一起交流学习~