You are not logged in.
I want to create C++ application with Cairo library, more precisely, with it's C++ counterpart, cairomm. I have it already installed in my system. It depends on libsigc++, which is also installed. I'm pretty sure it's working, because apps that depend on, such as gparted, work.
So I wrote small piece of code to test it.
#include <cairomm/context.h>
#include <cairomm/surface.h>
#include <iostream>
int main() {
std::cout << "test" << std::endl;
return 0;
}
It didn't worked:
> clang main.cpp
main.cpp:1:10: fatal error: 'cairomm/context.h' file not found
#include <cairomm/context.h>
^~~~~~~~~~~~~~~~~~~
1 error generated.
At this point, I have already noticed that cairomm library is no in folder that I would expect: not in /usr/include/cairomm, but in /usr/include/cairomm-1.0/cairomm. Same goes for sigc++. I tried including this folders using something like:
clang -I/usr/include/cairomm-1.0/ -I/usr/include/sigc++-2.0 main.cpp
In file included from main.cpp:1:
In file included from /usr/include/cairomm-1.0/cairomm/context.h:24:
In file included from /usr/include/cairomm-1.0/cairomm/surface.h:32:
In file included from /usr/include/sigc++-2.0/sigc++/slot.h:19:
In file included from /usr/include/sigc++-2.0/sigc++/functors/slot.h:5:
/usr/include/sigc++-2.0/sigc++/trackable.h:22:10: fatal error: 'sigc++config.h' file not found
#include <sigc++config.h>
^~~~~~~~~~~~~~~~
1 error generated.
But as you can see, it didn't help.
I did some googling and found that gparted uses some GTKMM_LIBS (or something) variable in it's makefiles, and googling it showed that gtkmm is being compiled using result from pkg-config.
So what it is? Is there some simple flag I missed (like -Icairomm), or I have to use this pkg-config, or is there other way to properly compile project that uses cairomm?
Why people place their libraries in such folder hierarchy?
What is pkg-config and how it is helpful in building projects, and why can't (or can) I survive without it?
Last edited by SuperPrower (2017-12-09 18:20:12)
Offline
...
So what it is? Is there some simple flag I missed (like -Icairomm),
...
Yes. If you are not linking the library, the files wont be found. Make sure everything is linked properly first and try again. Otherwise no idea unfortunately.
I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.
Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...
Offline
Did you check the Wikipedia entry? https://en.wikipedia.org/wiki/Pkg-config
pkg-config abstracts information about installed libraries in the system. Not all libraries will be installed in /usr/include and /usr/lib, they can have arbitrary locations depending on circumstances. They can also depend on other libraries. pkg-config allows to retrieve information about a library: paths, compiler flags, dependencies without having to guess them.
With your simple command line you are supposed to use it like this:
clang++ main.cpp $(pkg-config --cflags --libs cairomm-1.0)
If you run the subcommand separately, you'll see that you needed to add a lot more options than cairomm itself, and pkg-config handled the dependencies automatically.
Offline
Did you check the Wikipedia entry? https://en.wikipedia.org/wiki/Pkg-config
pkg-config abstracts information about installed libraries in the system. Not all libraries will be installed in /usr/include and /usr/lib, they can have arbitrary locations depending on circumstances. They can also depend on other libraries. pkg-config allows to retrieve information about a library: paths, compiler flags, dependencies without having to guess them.
With your simple command line you are supposed to use it like this:
clang++ main.cpp $(pkg-config --cflags --libs cairomm-1.0)
If you run the subcommand separately, you'll see that you needed to add a lot more options than cairomm itself, and pkg-config handled the dependencies automatically.
Thanks.
This sure is... weird, but understandable.
But why do I need both --cflags and --libs?
I mean, just using --libs doesn't work for some reason (it just can't find library), but with other libs, such as SFML, it was enough; --cflags, on the other hand, works without --libs.
Offline
--cflags gives additional include search paths and macro definitions for the library (-I/-D). --libs gives additional library search paths and library names (-L/-l). See "man pkg-config".
The first should be passed during compilation, the second should be passed during linking of your program. Since you have a simple command line that does both compilation and linking, both options need to be used.
pkg-config is not weird, it solves a lot of problems. Consider a case when you need libpng 1.2 and libpng 1.6 on the system. Both provide png.h and would conflict in /usr/include. But placing the headers in /usr/include/libpng[12|16] and adding a .pc configuration file solves this problem. Now programs only need to request libpng12 or libpng16 from pkg-config.
Similarly, libraries have dependencies that can also vary from system to system, and these dependencies have their own dependencies etc. By using pkg-config you don't need to think about how to add the dependent libraries.
You can think of pkg-config as of a "package manager" interface to installed libraries.
Offline