简体   繁体   中英

How are C libraries installed?

sorry for stupid question, but I have been writing programs in other languages and now that I am starting to get into C, I would like to know this.

I am on Arch (sorry to be that guy, I think it matters), and pretty new to it, but I need to install library. Are libraries packages, or should I get them from somewhere like github? What is propper procedure? Library in question is libgimp/gimp.h

Thanks in advance.

Run:

$sudo pacman -S gimp

And then:

$ ls -l usr/include/gimp-2.0/libgimp/
usr/include/gimp-2.0/libgimp/gimp.h
usr/include/gimp-2.0/libgimp/gimp_pdb.h
usr/include/gimp-2.0/libgimp/gimp_pdb_headers.h
usr/include/gimp-2.0/libgimp/gimpaspectpreview.h
usr/include/gimp-2.0/libgimp/gimpbrush_pdb.h
usr/include/gimp-2.0/libgimp/gimpbrushes.h
usr/include/gimp-2.0/libgimp/gimpbrushes_pdb.h
usr/include/gimp-2.0/libgimp/gimpbrushmenu.h
usr/include/gimp-2.0/libgimp/gimpbrushselect.h
usr/include/gimp-2.0/libgimp/gimpbrushselect_pd
...

You will have to provide the compiler flag

-I/usr/include/gimp-2.0

And the linker flag:

-lgimp-2.0 -lgimpbase-2.0

Note: Always include files this way:

#include <libgimp/file_name.h>

eg:

#include <libgimp/gimp.h>

Update: As requested by another user, I am attaching the instructions in terms of pkg-config (not a big user myself but it's a great tool):

$ pkg-config --cflags gimp-2.0
-I/usr/include/gimp-2.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/cairo -I/usr/include/lzo -I/usr/include/freetype2 -I/usr/include/harfbuzz -I/usr/include/pixman-1 -I/usr/include/gegl-0.4 -I/usr/include/gio-unix-2.0 -I/usr/include/json-glib-1.0 -pthread -I/usr/include/babl-0.1 
$ pkg-config --libs gimp-2.0
-lgimp-2.0 -lgimpmath-2.0 -lgimpconfig-2.0 -lgimpcolor-2.0 -lgimpbase-2.0 -lgdk_pixbuf-2.0 -lcairo -lgegl-0.4 -lgegl-npd-0.4 -lm -Wl,--export-dynamic -lgmodule-2.0 -pthread -lglib-2.0 -ljson-glib-1.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lbabl-0.1 

So you may just pass that to your compiler:

GIMP_INCLUDES=$(pkg-config --cflags gimp-2.0)
GIMP_LIBS=$(pkg-config --libs gimp-2.0)
g++ myfile.cpp $GIMP_INCLUDES myfile.o
g++ myfile.o $GIMP_LIBS -o main 

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