pkg-config with Gtk

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

pkg-config with Gtk

Frank Hrebabetzky-2
I use mingw every now and then, so I might have overseen something.

I wrote a simple dll 'libio' which calls glib and glibc and exports some
basic file IO functions to be used from another programming language.

Compilation went fine.

Linking with
   gcc `pkg-config --libs glib-2.0` -shared -o libio.dll libio.o
-Wl,--out-implib,libio.a
produced
   libio.o:libio.c:(.text+0x24): undefined reference to 'g_fopen'

So I called
   pkg-config --libs glib-2.0
which responded
   -Lc:/Programs/Gtk/lib -lglib-2.0 -lintl

In this directory I found the file glib-2.0.def which in fact doesnt't
contain the symbol 'g_fopen'. Now if I look into
   c:/Programs/Gtk/bin/lglib-2.0-0.dll
with Dependency Walker I find 'g_fopen'.

So I tried to link with
   gcc -Wall -Lc:/Programs/Gtk/bin -lglib-2.0-0 -shared libio.o -o libio.dll
and it worked.

The problem is that I want to call other Gtk libraries in future, where
pkg-config produces several lines of output.

Do I have to translate all that by hand as in the example above?
Am I missing something with the use of pkg-config or is it a bug?
--
Frank

------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: pkg-config with Gtk

John Brown

Hello Frank,

This is strange. What do you have in  c:/Programs/GTK/lib other than
the .def file? Do you see a file called libglib-2.0.dll.a or similar?

Regards,
Alias John Brown.
     
------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its
next-generation tools to help Windows* and Linux* C/C++ and Fortran
developers boost performance applications - including clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: pkg-config with Gtk

Tor Lillqvist
In reply to this post by Frank Hrebabetzky-2
> Linking with
> gcc `pkg-config --libs glib-2.0` -shared -o libio.dll libio.o -Wl,--out-implib,libio.a
> produced
>  libio.o:libio.c:(.text+0x24): undefined reference to 'g_fopen'

You should pass a -l option *after* the object file(s) that need stuff
from the library in question. This is how Unix-style linkers have
always worked. Read the gcc and/or ld documentation.

In many cases you can manage on Linux even if you put the -l option
before the object files, which is why many people have forgotten the
old rule, and think the Linux behaviour is the only one. This subject
comes up on this list several times a month it seems...

> In this directory I found the file glib-2.0.def which in fact doesnt't
> contain the symbol 'g_fopen'.

Where does this glib-2.0.def file come from? In the lib/glib-2.0.def
files from the "official" GLib 32-bit Windows packages I did when I
still did that, I do see g_fopen.

> So I tried to link with
>   gcc -Wall -Lc:/Programs/Gtk/bin -lglib-2.0-0 -shared libio.o -o libio.dll
> and it worked.

Maybe in the case of linking "directly" to a DLL, ld works in such a
way that it doesn't matter that you had the -l option referencing the
DLL before the object files?

> Do I have to translate all that by hand as in the example above?
> Am I missing something with the use of pkg-config or is it a bug?

Just put all the pkg-config --libs output *after* the object files on
the linking command line and you will be fine. This works on all Unix
platforms, too, so just learn to do it that way.

--tml

------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its
next-generation tools to help Windows* and Linux* C/C++ and Fortran
developers boost performance applications - including clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: pkg-config with Gtk

Frank Hrebabetzky-2
In reply to this post by John Brown
I have the standard binary Gtk+ all-in-one bundle version 2.22 for win32
installed.
'ls c:/Programs/Gtk/lib/*glib*' yields:
   glib-2.0.def
   glib-2.0.lib
   libglib-2.0.dll.a
and the directory
   glib-2.0

--
Frank

On 5/17/2011 5:05 PM, John Brown wrote:

>
> Hello Frank,
>
> This is strange. What do you have in  c:/Programs/GTK/lib other than
> the .def file? Do you see a file called libglib-2.0.dll.a or similar?
>
> Regards,
> Alias John Brown.
>    
> ------------------------------------------------------------------------------
> What Every C/C++ and Fortran developer Should Know!
> Read this article and learn how Intel has extended the reach of its
> next-generation tools to help Windows* and Linux* C/C++ and Fortran
> developers boost performance applications - including clusters.
> http://p.sf.net/sfu/intel-dev2devmay
> _______________________________________________
> MinGW-users mailing list
> [hidden email]
>
> This list observes the Etiquette found at
> http://www.mingw.org/Mailing_Lists.
> We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.
>
> _______________________________________________
> You may change your MinGW Account Options or unsubscribe at:
> https://lists.sourceforge.net/lists/listinfo/mingw-users
> Also: mailto:[hidden email]?subject=unsubscribe
>

------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its
next-generation tools to help Windows* and Linux* C/C++ and Fortran
developers boost performance applications - including clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: pkg-config with Gtk

Frank Hrebabetzky-2
In reply to this post by Tor Lillqvist

On 5/17/2011 5:35 PM, Tor Lillqvist wrote:
> Just put all the pkg-config --libs output *after* the object files on
> the linking command line and you will be fine. This works on all Unix
> platforms, too, so just learn to do it that way.

It works now. Thanks for the hint.
--
Frank

------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its
next-generation tools to help Windows* and Linux* C/C++ and Fortran
developers boost performance applications - including clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: pkg-config with Gtk

Keith Marshall
In reply to this post by Tor Lillqvist
On 17/05/11 21:35, Tor Lillqvist wrote:

>> Linking with
>> > gcc `pkg-config --libs glib-2.0` -shared -o libio.dll libio.o -Wl,--out-implib,libio.a
>> > produced
>> >  libio.o:libio.c:(.text+0x24): undefined reference to 'g_fopen'
> You should pass a -l option *after* the object file(s) that need stuff
> from the library in question. This is how Unix-style linkers have
> always worked. Read the gcc and/or ld documentation.
>
> In many cases you can manage on Linux even if you put the -l option
> before the object files, ...

Specifically, you may get away with it when the library in question is a
shared object.  However, getting away with it doesn't make it right.  It
isn't; it is still an error, and even the Linux linker will punish you
just as severely, if you commit the same error with a statically linked
library.

> ... which is why many people have forgotten the old rule, and think
> the Linux behaviour is the only one. This subject comes up on this
> list several times a month it seems...

Indeed, far too often.  This quirky misfeature of the Linux linker has
much to answer for, in terms of broken build-it-yourself software packages.

--
Regards,
Keith.

------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its
next-generation tools to help Windows* and Linux* C/C++ and Fortran
developers boost performance applications - including clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: pkg-config with Gtk

Dieter Verfaillie
In reply to this post by Frank Hrebabetzky-2
Quoting "Frank Hrebabetzky" <[hidden email]>:

> The problem is that I want to call other Gtk libraries in future, where
> pkg-config produces several lines of output.

See https://bugs.freedesktop.org/show_bug.cgi?id=17053
the patch from comment 3 should be reverted.

mvg,
Dieter

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its
next-generation tools to help Windows* and Linux* C/C++ and Fortran
developers boost performance applications - including clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe