简体   繁体   中英

XCode with pkg-config

Hi I am using gtkmm in an XCode project and I am wondering how I can include the headers without using the command line and adding them in manually. Is there a way to using pkgconfig in XCode without doing it this way, ie some extra params or something?

Any help would be appreciated.

May be look here

You can use pkg-config , if a .pc file for that package is present. These files are generally located at /usr/share/pkgconfig . You can prepare your own .pc file also by writing the header files directory and library directory in a specified format.

Just have a look at the contents of a .pc file and it it intuitive to understand.

I know that this is old, but I was able to get gtkmm working in Xcode 6 so I figured I'd share.

Assuming that gtkmm and Xcode 6 has been installed on your mac, the following steps should allow you to add gtkmm to an existing Xcode (c++) project.

Run pkg-config <pkgconfig file name> —cflags —libs in the terminal. This command returns the linker flags/compiler flags Xcode will need. I have gtkmm 2.24.2_1 installed on my machine so for me the command is pkg-config gtkmm-2.4 —cflags —libs for me. I cannot guarantee that this works for other versions.

To determine the name of your .pc file, mine was located inside /usr/local/Cellar/gtkmm/2.24.4_1/lib/pkgconfig

The terminal command should return all the required flags, here's what mine returns:

-D_REENTRANT -I/usr/local/Cellar/gtkmm/2.24.4_1/include/gtkmm-2.4 -I/usr/local/Cellar/gtkmm/2.24.4_1/lib/gtkmm-2.4/include -I/usr/local/Cellar/atkmm/2.22.7/include/atkmm-1.6 -I/usr/local/Cellar/gtk+/2.24.28_2/include/gtk-unix-print-2.0 -I/usr/local/Cellar/gtk+/2.24.28_2/include/gtk-2.0 -I/usr/local/Cellar/gtkmm/2.24.4_1/include/gdkmm-2.4 -I/usr/local/Cellar/gtkmm/2.24.4_1/lib/gdkmm-2.4/include -I/usr/local/Cellar/glibmm/2.44.0/include/giomm-2.4 -I/usr/local/Cellar/glibmm/2.44.0/lib/giomm-2.4/include -I/usr/local/Cellar/pangomm/2.36.0/include/pangomm-1.4 -I/usr/local/Cellar/pangomm/2.36.0/lib/pangomm-1.4/include -I/usr/local/Cellar/glibmm/2.44.0/include/glibmm-2.4 -I/usr/local/Cellar/glibmm/2.44.0/lib/glibmm-2.4/include -I/usr/local/Cellar/cairomm/1.11.2_1/include/cairomm-1.0 -I/usr/local/Cellar/cairomm/1.11.2_1/lib/cairomm-1.0/include -I/usr/local/Cellar/libsigc++/2.4.1/include/sigc++-2.0 -I/usr/local/Cellar/libsigc++/2.4.1/lib/sigc++-2.0/include -I/usr/local/Cellar/gtk+/2.24.28_2/incl ude/gtk-2.0 -I/usr/local/Cellar/gtk+/2.24.28_2/lib/gtk-2.0/include -I/usr/local/Cellar/pango/1.36.8_1/include/pango-1.0 -I/usr/local/Cellar/atk/2.16.0/include/atk-1.0 -I/usr/local/Cellar/cairo/1.14.2_1/include/cairo -I/usr/local/Cellar/pixman/0.32.6/include/pixman-1 -I/usr/local/Cellar/fontconfig/2.11.1/include -I/usr/local/Cellar/freetype/2.5.3_1/include/freetype2 -I/usr/local/Cellar/freetype/2.6_1/include/freetype2 -I/usr/local/Cellar/libpng/1.6.17/include/libpng16 -I/usr/local/Cellar/gdk-pixbuf/2.30.8/include/gdk-pixbuf-2.0 -I/usr/local/Cellar/libpng/1.6.17/include/libpng16 -I/usr/local/Cellar/glib/2.44.1/include/glib-2.0 -I/usr/local/Cellar/glib/2.44.1/lib/glib-2.0/include -I/usr/local/opt/gettext/include -L/usr/local/Cellar/gtkmm/2.24.4_1/lib -L/usr/local/Cellar/atkmm/2.22.7/lib -L/usr/local/Cellar/gtk+/2.24.28_2/lib -L/usr/local/Cellar/gtkmm/2.24.4_1/lib -L/usr/local/Cellar/glibmm/2.44.0/lib -L/usr/local/Cellar/pangomm/2.36.0/lib -L/usr/local/Cellar/glibmm/2.44.0/lib -L/usr/local /Cellar/cairomm/1.11.2_1/lib -L/usr/local/Cellar/libsigc++/2.4.1/lib -L/usr/local/Cellar/gtk+/2.24.28_2/lib -L/usr/local/Cellar/pango/1.36.8_1/lib -L/usr/local/Cellar/atk/2.16.0/lib -L/usr/local/Cellar/cairo/1.14.2_1/lib -L/usr/local/Cellar/gdk-pixbuf/2.30.8/lib -L/usr/local/Cellar/glib/2.44.1/lib -L/usr/local/opt/gettext/lib -lgtkmm-2.4 -latkmm-1.6 -lgtk-quartz-2.0 -lgdkmm-2.4 -lgiomm-2.4 -lpangomm-1.4 -lglibmm-2.4 -lcairomm-1.0 -lsigc-2.0 -lgtk-quartz-2.0 -lgdk-quartz-2.0 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl

Now in Xcode open your project file and select your target, within build settings you then need to copy the flags you got from the terminal into “Other Linker Flags” and “Other C Flags”

At this point you should be able to run, compile, build, etc. c++ projects that use gtkmm in Xcode.

Answer based on the details from user2618142's answer + link

Also just as an aside, if you are getting the error

no matching constructor for initialization of 'GTK::Main'

on the line Gtk::Main kit( argc, argv ) it is likely because Xcode by default creates a main like this int main(int argc, const char * argv[]) but gtkmm uses argv as a non const parameter, so you need to change your main function to int main(int argc, char * argv[]) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM