C++ 如何在 OSX 上安装 gtk 以与 g++/gcc 编译器一起使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20098862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install gtk on OSX for use with g++/gcc compiler
提问by tmuecksch
I already asked this question at apple.stackexchange.com, but I was told it was the wrong place for this question - so I will ask it here, as I was suggested to do.
我已经在 apple.stackexchange.com 上问过这个问题,但我被告知这是这个问题的错误地方 - 所以我会在这里问,因为我被建议这样做。
At my university we got the task to implement a c-program which has a GTK-GUI. The GTK-GUI is already implemented, we just have to implement a algorithm which hands it some data.
在我的大学,我们接到了一个任务来实现一个带有 GTK-GUI 的 c 程序。GTK-GUI 已经实现,我们只需要实现一个算法来传递一些数据。
I already got gcc/g++ working. But when i try to compile the project the compiler returns the error, that it does not find the gtk:
我已经让 gcc/g++ 工作了。但是当我尝试编译项目时,编译器返回错误,它没有找到 gtk:
fatal error: 'gtk/gtk.h' file not found
#include <gtk/gtk.h>
^
So my question is:How do I install gtk on OSX Mavericks for using it with gcc/g++ compiler?
所以我的问题是:如何在 OSX Mavericks 上安装 gtk 以便与 gcc/g++ 编译器一起使用?
My setup: MacBook Pro Retina Mid 2012 with OSX Mavericks. Homebrew is installed and working if it could be useful for the installation.
我的设置:配备 OSX Mavericks 的 MacBook Pro Retina Mid 2012。如果 Homebrew 对安装有用,则安装并运行。
(Of course the Apple Command Line Developer Tools are installed)
(当然安装了苹果命令行开发工具)
回答by tmuecksch
I finally solved the Problem. tojanfoe suggested in a comment the link http://www.hardcoded.net/devlogs/20120426which turned out to not be helpful.
我终于解决了问题。tojanfoe 在评论中建议链接http://www.hardcoded.net/devlogs/20120426,结果证明没有帮助。
This is how i solved it:
我是这样解决的:
1.a) Installation of GTK+ 2.x:
1.a) GTK+ 2.x 的安装:
brew install gtk+
1.b) Installation of GTK+ 3.x:
1.b) 安装 GTK+ 3.x:
You can install gtk+ 3.x via home brew too if you need that, but the 2.x version is enough for my purposes. The command would be:
如果需要,您也可以通过 home brew 安装 gtk+ 3.x,但 2.x 版本足以满足我的目的。命令将是:
brew install gtk+3
2.) But after the installation I had the problem, that cairo could not be found. So i solved it this way:
2.) 但是安装后我遇到了问题,找不到cairo。所以我是这样解决的:
export PKG_CONFIG_PATH=/usr/local/Cellar/cairo/1.12.16/lib/pkgconfig/
3.) Then the compiler said it could not find the package 'xcb-shm', required by 'cairo'. This can be solved this way:
3.) 然后编译器说它找不到'cairo'所需的'xcb-shm'包。这可以通过以下方式解决:
export PKG_CONFIG_PATH=/usr/X11/lib/pkgconfig
After this command the compiler worked as expected.
执行此命令后,编译器按预期工作。
回答by ERET1K
You can download precompiled Gtk2 Framework from: http://r.research.att.comhttp://r.research.att.com/libs/GTK_2.24.17-X11.pkg, or http://r.research.att.com/libs/GTK_2.18.5-X11.pkg
:您可以从预编译Gtk2的视觉框架http://r.research.att.com http://r.research.att.com/libs/GTK_2.24.17-X11.pkg,或 HTTP://r.research。 att.com/libs/GTK_2.18.5-X11.pkg
And Gtk3 Framework from: http://www.tarnyko.net/dl/gtk.htm
和 Gtk3 框架来自:http://www.tarnyko.net/dl/gtk.htm