2

I am almost complete noob in linux world and I use Ubuntu 14.04 LTS with gnome-session-fallback (compiz) under VirtualBox on Windows 8.1 machine. My goal is to use this library: https://github.com/akrinke/svg2cairo

The only thing I need is to compile 'svg2cairoxml.c'. Here is very simplified version of this file:

#include <stdio.h>
#include <stdlib.h>
#include <librsvg/rsvg.h>
#include <cairo/cairo.h>

int main(int argc, char *argv[]) {
    return 0;
}

I tried to use Code::Blocks 13.12 and Anjuta 3.10.2 with no success. Both of them producing error "fatal error: librsvg/rsvg.h: No such file or directory" on compilation. I managed to find this file under another location: 'librsvg-2.0/librsvg/rsvg.h'. So I changed 3rd line of the code above. Later I installed gtk dev library following stackoverflow answer. And then I encountered error which I can't resolve: "fatal error: glib-object.h: No such file or directory" in the file 'rsvg.h':

// this is line 31
#include <glib-object.h>

I also located this file, the real path is 'glib-2.0\glib-object.h'. But the thing is 'rsvg.h' is protected so I can't change it. And this is where i'm stuck.

Also I found this instructions:

https://stackoverflow.com/questions/7537008/compilation-error-while-using-librsvg But those are too complicated for noob like me.

I think my goal (to compile the only small 'svg2cairoxml.c' file) is pretty easy for experienced linux programmers. So can someone please help me to do it? Also I guess I'm doing something wrong like using wrong version of libraries or something like this.

  • 2
    You shouldn't need to edit any of the .h files - it's a matter of adding the appropriate include paths to your Code::Blocks project configuration equivalent to adding -I/usr/include/librsvg-2.0/ -I/usr/include/glib-2.0/ to the compiler commandline. – steeldriver Mar 25 '15 at 21:32
  • Forgot to mention: I also installed necessary 'librsvg2*' packages from software center. – YuriM Mar 25 '15 at 21:34
  • 1
    the compile step needs to have (for gcc compiler) parameters of the '-Ipathtoheaderfile' variety. Then when the compile has no errors/warnings (enable all warnings and correct them) then the link step needs a combination of two parameters: 1) '-Lpathtolibrary' and 2) '-llibname' where '-l is a lowercase L and libname is the library name without the leading 'lib' nor the trailing .so or .a I.E. libmath.so would be included via '-lmath' – user3629249 Mar 25 '15 at 21:35
  • 1
    Try compiling from the command-line using gcc svg2cairoxml.c `pkg-config --cflags --libs librsvg-2.0`: if that works, then it is just a matter of modifying your IDE's settings accordingly. – steeldriver Mar 25 '15 at 21:42
  • 1
    "gcc svg2cairoxml.c..." command produces "a.out" which actually works printing program usage. So I just need to know my IDE better. Thank you both for so quickly and useful answers. – YuriM Mar 25 '15 at 22:12
2

When a development package installs its header and/or library files in places that are not directly on the standard compiler search path, you need to specify the locations yourself explicitly. To do that on the gcc command line for example, you would use suitable -I (include path) and -L (library path) directives. You also need to tell the linker which specific libraries to link from those search paths using -l directives such as -lrsvg-2 for librsvg-2.

Since paths and libraries can become quite complex, and vary depending on the exact platform, some development packages provide a package configuration (.pc) file that can be interrogated by the pkg-config utility to generate the appropriate directives at build time. The librsvg-dev package is one such, so to build your simple program on the command-line all that's required is

gcc svg2cairoxml.c `pkg-config --cflags --libs librsvg-2.0`

To achieve the same within your IDE, you have a couple of options: you can either run

pkg-config --cflags librsvg-2.0

and

pkg-config --libs librsvg-2.0

in a terminal and copy the resulting output into the appropriate compiler and linker settings boxes or, following this answer to a similar question on StackOverflow How to setup GTK+ to develop with Code::Blocks on Ubuntu Linux, add the pkg-config command substitutions directly to the Other options tab as follows:

Code::Blocks pkg-config --cflags setting

enter image description here

  • Wow, you wrote an article to answer the question. Thanks a lot, steeldriver. – YuriM Mar 26 '15 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.