gpt4 book ai didi

c++ - 使用 Homebrew 安装 C++ 库

转载 作者:太空狗 更新时间:2023-10-29 20:37:24 24 4
gpt4 key购买 nike

我正在尝试为我的项目安装一个 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>

header 位于 ~/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>在我的源文件中。

但是还是编译不出来

我该怎么办?

最佳答案

是的,像这样使用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

关于c++ - 使用 Homebrew 安装 C++ 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34874825/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com