help needed to compile a C program

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

help needed to compile a C program

macports-2
I'm trying to use DejaVu fonts in rrdtool and it fails; rrdtool depends on pango, and currently I think that pango is my bottleneck.
To verify this I found a tiny program (https://www.lemoda.net/pango/list-fonts/index.html) that fails to compile.

---
#include <glib.h>
#include <pango/pangocairo.h>

static void
list_fonts ()
{
    int i;
    PangoFontFamily ** families;
    int n_families;
    PangoFontMap * fontmap;

    fontmap = pango_cairo_font_map_get_default();
    pango_font_map_list_families (fontmap, & families, & n_families);
    printf ("There are %d families\n", n_families);
    for (i = 0; i < n_families; i++) {
        PangoFontFamily * family = families[i];
        const char * family_name;

        family_name = pango_font_family_get_name (family);
        printf ("Family %d: %s\n", i, family_name);
    }
    g_free (families);
}

int main (int argc, char ** argv)
{
    list_fonts ();
    return 0;
}
---

with makefile:
---
pango-list-typefaces:   pango-list-typefaces.c
        cc -o $@ -Wall -g pango-list-typefaces.c \
        $(pkg-config --cflags --libs pango) \
        $(pkg-config --cflags --libs cairo) \
        $(pkg-config --cflags --libs pangocairo) \Currently 
        $(pkg-config --cflags --libs glib-2.0)
---

and error:
---
make pango-list-typefaces
cc     pango-list-typefaces.c   -o pango-list-typefaces
pango-list-typefaces.c:1:10: fatal error: 'glib.h' file not found
#include "glib.h"
         ^
1 error generated.
---


- What does Macports do for includes/libraries/etc, or -if nothing- what should I do to use them from Macports?

Currently I have glib2 installed, but there is also glib2-devel, and they conflict with each other.
Same for pango and pango-devel.
- What is the difference?
- Which should I use?

I don't know what the include path will be. 
- How should I use 'port provides glib.h' ?



Reply | Threaded
Open this post in threaded view
|

Re: help needed to compile a C program

Rainer Müller-4
On 2018-04-13 18:21, [hidden email] wrote:
> with makefile:
> ---
> pango-list-typefaces:   pango-list-typefaces.c
>         cc -o $@ -Wall -g pango-list-typefaces.c \
>         $(pkg-config --cflags --libs pango) \
>         $(pkg-config --cflags --libs cairo) \
>         $(pkg-config --cflags --libs pangocairo) \Currently 
>         $(pkg-config --cflags --libs glib-2.0)

The Makefile is your problem. $(foo) is a normal variable expansion.
This should be: $(shell pkg-config ...)

Rainer
Reply | Threaded
Open this post in threaded view
|

Re: help needed to compile a C program

macports-2

> On 2018-04-13, at 20:17, Rainer Müller <[hidden email]> wrote:
>
> On 2018-04-13 18:21, [hidden email] wrote:
>> with makefile:
>> ---
>> pango-list-typefaces:   pango-list-typefaces.c
>>         cc -o $@ -Wall -g pango-list-typefaces.c \
>>         $(pkg-config --cflags --libs pango) \
>>         $(pkg-config --cflags --libs cairo) \
>>         $(pkg-config --cflags --libs pangocairo) \Currently
>>         $(pkg-config --cflags --libs glib-2.0)
>
> The Makefile is your problem. $(foo) is a normal variable expansion.
> This should be: $(shell pkg-config ...)
>
> Rainer

my mistake: I changed `pkg-config ..` to $(..).
but neither $(shell pkg-config nor `pkg-config helped. same error.
question remains open.

any suggestions on my aother questions?

Currently I have glib2 installed, but there is also glib2-devel, and they conflict with each other.
Same for pango and pango-devel.
- What is the difference?
- Which should I use?

I don't know what the include path will be.
- How should I use 'port provides glib.h' ?
Reply | Threaded
Open this post in threaded view
|

Re: help needed to compile a C program

Rainer Müller-4
On 2018-04-13 21:26, [hidden email] wrote:

>
>> On 2018-04-13, at 20:17, Rainer Müller <[hidden email]> wrote:
>>
>> On 2018-04-13 18:21, [hidden email] wrote:
>>> with makefile:
>>> ---
>>> pango-list-typefaces:   pango-list-typefaces.c
>>>         cc -o $@ -Wall -g pango-list-typefaces.c \
>>>         $(pkg-config --cflags --libs pango) \
>>>         $(pkg-config --cflags --libs cairo) \
>>>         $(pkg-config --cflags --libs pangocairo) \Currently
>>>         $(pkg-config --cflags --libs glib-2.0)
>>
>> The Makefile is your problem. $(foo) is a normal variable expansion.
>> This should be: $(shell pkg-config ...)
>>
>> Rainer
>
> my mistake: I changed `pkg-config ..` to $(..).
> but neither $(shell pkg-config nor `pkg-config helped. same error.
> question remains open.

Works for me. Use "Download ZIP" to the upper right here, extract and
run make in the directory:
https://gist.github.com/raimue/634213828f7ff86b9a6f4698ed488d85
> any suggestions on my aother questions?
>
> Currently I have glib2 installed, but there is also glib2-devel, and they conflict with each other.
> Same for pango and pango-devel.
> - What is the difference?
> - Which should I use?

*-devel ports are pre-releases, beta or unstable. You usually do not
want them unless you really need the bleeding edge.

> I don't know what the include path will be.
> - How should I use 'port provides glib.h' ?

Use an absolute path:

$ port provides /opt/local/include/glib-2.0/glib.h
/opt/local/include/glib-2.0/glib.h is provided by: glib2

If instead you meant you do not know which ports provides a specific
file, there is unfortunately no index available for that.

Rainer
Reply | Threaded
Open this post in threaded view
|

Re: help needed to compile a C program

Ryan Schmidt-24
In reply to this post by macports-2

On Apr 13, 2018, at 14:26, [hidden email] wrote:

> On 2018-04-13, at 20:17, Rainer Müller wrote:
>
>> On 2018-04-13 18:21, [hidden email] wrote:
>>> with makefile:
>>> ---
>>> pango-list-typefaces:   pango-list-typefaces.c
>>>        cc -o $@ -Wall -g pango-list-typefaces.c \
>>>        $(pkg-config --cflags --libs pango) \
>>>        $(pkg-config --cflags --libs cairo) \
>>>        $(pkg-config --cflags --libs pangocairo) \Currently

Remove the word "Currently"

>>>        $(pkg-config --cflags --libs glib-2.0)
>>
>> The Makefile is your problem. $(foo) is a normal variable expansion.
>> This should be: $(shell pkg-config ...)
>>
>> Rainer
>
> my mistake: I changed `pkg-config ..` to $(..).
> but neither $(shell pkg-config nor `pkg-config helped. same error.
> question remains open.

pkg-config should be adding all the necessary flags. For example:

$ pkg-config --cflags --libs glib-2.0
-I/opt/local/include/glib-2.0 -I/opt/local/lib/glib-2.0/include -I/opt/local/include -L/opt/local/lib -lglib-2.0 -lintl -Wl,-framework -Wl,CoreFoundation



> any suggestions on my aother questions?
>
> Currently I have glib2 installed, but there is also glib2-devel, and they conflict with each other.
> Same for pango and pango-devel.
> - What is the difference?
> - Which should I use?

glib2 and pango are the latest stable versions. glib2-devel and pango-devel are the latest development versions. At this moment in time, they happen to provide the same versions.


> I don't know what the include path will be.
> - How should I use 'port provides glib.h' ?

port provides takes absolute paths:

$ port provides /opt/local/include/glib-2.0/glib.h
/opt/local/include/glib-2.0/glib.h is provided by: glib2