用自制软件安装C ++库

时间:2016-01-19 10:50:00

标签: c++ macos homebrew

我尝试为我的项目安装C ++库( gtkmm ),并使用一个简单的测试文件(维基百科页面中关于gtkmm的主页)来测试此安装。 我做了brew install gtkmm3,它安装了它,但是当我使用clang++ -Wall -Werror -Wextra -o test test.cpp进行编译时,它找不到我的标题:

test.cpp:15:10: fatal error: 'gtkmm-3.0/gtkmm.h' file not found
#include <gtkmm-3.0/gtkmm.h>

标题位于~/homebrew/include/gtkmm-3.0/gtkmm.h。 我试过了:

  • $HOME"/homebrew/include"添加到$PATH并在我的源文件中使用#include <gtkmm-3.0/gtkmm.h>

  • $HOME"/homebrew/include/gtkmm-3.0"添加到我的$PATH并在我的源文件中使用#include <gtkmm.h>

但我仍然无法编译。

我该怎么办?

1 个答案:

答案 0 :(得分:4)

是的,请像这样使用pkgconfig,它会告诉您所需的所有包含路径和链接路径:

pkg-config --libs --cflags /usr/local/Cellar/gtkmm3/*/lib/pkgconfig/gdkmm-3.0.pc

<强>输出

-D_REENTRANT -I/usr/local/Cellar/gtkmm3/3.18.0/include/gdkmm-3.0 
-I/usr/local/Cellar/gtkmm3/3.18.0/lib/gdkmm-3.0/include 
-I/usr/local/Cellar/glibmm/2.46.3/include/giomm-2.4 
-I/usr/local/Cellar/glibmm/2.46.3/lib/giomm-2.4/include 
-I/usr/local/Cellar/pangomm/2.38.1/include/pangomm-1.4 
-I/usr/local/Cellar/pangomm/2.38.1/lib/pangomm-1.4/include 
-I/usr/local/Cellar/glibmm/2.46.3/include/glibmm-2.4 
-I/usr/local/Cellar/glibmm/2.46.3/lib/glibmm-2.4/include 
-I/usr/local/Cellar/gtk+3/3.18.6/include/gtk-3.0 
-I/usr/local/Cellar/glib/2.46.2/include/gio-unix-2.0/ 
-I/usr/local/Cellar/cairo/1.14.6/include/cairo  
-I/usr/local/Cellar/libepoxy/1.3.1/include 
-I/usr/local/Cellar/pango/1.38.1/include/pango-1.0 
-I/usr/local/Cellar/harfbuzz/1.1.3/include/harfbuzz 
-I/usr/local/Cellar/pango/1.38.1/include/pango-1.0 
-I/usr/local/Cellar/atk/2.18.0/include/atk-1.0 
-I/usr/local/Cellar/cairo/1.14.6/include/cairo 
-I/usr/local/Cellar/cairomm/1.12.0/include/cairomm-1.0 
-I/usr/local/Cellar/cairomm/1.12.0/lib/cairomm-1.0/include 
-I/usr/local/Cellar/cairo/1.14.6/include/cairo 
-I/usr/local/Cellar/pixman/0.32.8/include/pixman-1 
-I/usr/local/Cellar/fontconfig/2.11.1/include 
-I/usr/local/Cellar/freetype/2.6_1/include/freetype2 
-I/usr/local/Cellar/libpng/1.6.20/include/libpng16 
-I/usr/local/Cellar/libsigc++/2.6.2/include/sigc++-2.0 
-I/usr/local/Cellar/libsigc++/2.6.2/lib/sigc++-2.0/include 
-I/usr/local/Cellar/gdk-pixbuf/2.32.3/include/gdk-pixbuf-2.0 
-I/usr/local/Cellar/libpng/1.6.20/include/libpng16 
-I/usr/local/Cellar/glib/2.46.2/include/glib-2.0 
-I/usr/local/Cellar/glib/2.46.2/lib/glib-2.0/include 
-I/usr/local/opt/gettext/include 
-L/usr/local/Cellar/gtkmm3/3.18.0/lib 
-L/usr/local/Cellar/glibmm/2.46.3/lib 
-L/usr/local/Cellar/pangomm/2.38.1/lib 
-L/usr/local/Cellar/glibmm/2.46.3/lib 
-L/usr/local/Cellar/gtk+3/3.18.6/lib 
-L/usr/local/Cellar/pango/1.38.1/lib 
-L/usr/local/Cellar/atk/2.18.0/lib 
-L/usr/local/Cellar/cairo/1.14.6/lib 
-L/usr/local/Cellar/glib/2.46.2/lib 
-L/usr/local/Cellar/cairomm/1.12.0/lib 
-L/usr/local/Cellar/cairo/1.14.6/lib 
-L/usr/local/Cellar/libsigc++/2.6.2/lib 
-L/usr/local/Cellar/gdk-pixbuf/2.32.3/lib 
-L/usr/local/Cellar/glib/2.46.2/lib 
-L/usr/local/opt/gettext/lib 
-lgdkmm-3.0 -lgiomm-2.4 -lpangomm-1.4 -lglibmm-2.4 -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lgio-2.0 -lcairomm-1.0 -lcairo -lsigc-2.0 -lgdk_pixbuf-2.0 -lgobject-2.0 -lglib-2.0 -lintl

然后你可以编译:

clang++ $(pkg-config --libs --cflags /usr/local/Cellar/gtkmm3/*/lib/pkgconfig/gdkmm-3.0.pc) someFile.cpp -o someFile