【问题标题】:Get error compiling example of gtk example from https://www.gtk.org/docs/getting-started/hello-world/从 https://www.gtk.org/docs/getting-started/hello-world/ 获取 gtk 示例的错误编译示例
【发布时间】:2020-06-01 08:00:15
【问题描述】:

您好,我正在尝试从官方网站编译 gtk 的 Hello World。我完成了所有要求,并通过 msys2 包管理器安装了 GTK。我的 cmd 无法检测到 package-config 目录。我已经在环境变量上为我的 msys264 设置了路径。如果我是初学者,这听起来令人困惑,我很抱歉。太清了。

C:\Users\60182\Desktop\vc>gcc `pkg-config --cflags gtk+-3.0` -o hello-world-gtk hello-world-gtk.c `pkg-config --libs gtk+-3.0`

gcc: error: `pkg-config: No such file or directory
gcc: error: gtk+-3.0`: No such file or directory
gcc: error: `pkg-config: No such file or directory
gcc: error: gtk+-3.0`: No such file or directory
gcc: error: unrecognized command-line option '--cflags'
gcc: error: unrecognized command-line option '--libs'

【问题讨论】:

    标签: c gtk3 msys2


    【解决方案1】:

    我可以看到问题。 Windows shell 不像 linux shell 那样工作。反引号字符用于将一个命令的输出作为参数传递给另一个。

    因此,为了手动执行此操作,您可以执行以下操作。首先运行命令pkg-config --cflags gtk+-3.0,然后运行pkg-config --libs gtk+-3.0。我不知道输出是什么,但假设输出只是“foo”和“bar”,看起来像这样:

    C:\Users\60182\Desktop\vc>pkg-config --cflags gtk+-3.0
    foo
    
    C:\Users\60182\Desktop\vc>pkg-config --libs gtk+-3.0
    bar
    

    然后你这样做:

    C:\Users\60182\Desktop\vc>gcc foo -o hello-world-gtk hello-world-gtk.c bar
    

    【讨论】:

    • 嗨,我试过你的建议,但我得到了这个 gcc:错误:foo:没有这样的文件或目录 gcc:错误:bar:没有这样的文件或目录
    • @user13626458 你得到了什么输出?
    • 你应该运行pkg-config --cflags gtk+-3.0 而不是pkg-config --cflags gtk+-3.0 foo。在我的示例中,foo 是输出。
    • 您好,我试过了,没有错误,但没有得到任何输出。
    • 然后运行gcc -o hello-world-gtk hello-world-gtk.c
    猜你喜欢
    • 2021-09-26
    • 1970-01-01
    • 2015-08-30
    • 2011-07-12
    • 2015-05-10
    • 2012-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多