Discussion:
Beyond gtk_init_check() - how do I tell if GTK is installed?
(too old to reply)
Charlie Gibbs
2015-10-01 06:43:40 UTC
Permalink
I've started learning how to write GTK code. One thing I noticed is
that where gtk_init() will terminate your program if it can't find a
display, gtk_init_check() will tell you whether it succeeded and let
you use other means (e.g. curses or a text-based interface) if not.
I've written a test program that uses this technique, and it works
fine - at least as long as GTK is installed. However, if GTK is
not installed, my program dies instantly. I think it's because it
can't find needed dynamic libraries; however, the machine on which
I tested it belongs to someone else who's now gone, and all of my
machines already have GTK installed so I can't easily reproduce the
condition.

In a perfect world, gtk_init_check() would contain enough statically
linked code that it could test for the presence of the GTK libraries
and return an appropriate error if they're absent. But I guess I'll
have to settle for some sort of programmatic test for the existence
of these libraries that won't nuke my program if they're not there.

Is there a way to do this? Can I coax the system to start executing
my program and not insist on the presence of dynamic libraries before
I need them, so I can check whether they're available? And how can I
check whether they're available?

aTdHvAaNnKcSe for any advice...
--
/~\ ***@kltpzyxm.invalid (Charlie Gibbs)
\ / I'm really at ac.dekanfrus if you read it the right way.
X Top-posted messages will probably be ignored. See RFC1855.
/ \ HTML will DEFINITELY be ignored. Join the ASCII ribbon campaign!
Richard Kettlewell
2015-10-01 08:30:10 UTC
Permalink
Post by Charlie Gibbs
I've started learning how to write GTK code. One thing I noticed is
that where gtk_init() will terminate your program if it can't find a
display, gtk_init_check() will tell you whether it succeeded and let
you use other means (e.g. curses or a text-based interface) if not.
I've written a test program that uses this technique, and it works
fine - at least as long as GTK is installed. However, if GTK is
not installed, my program dies instantly. I think it's because it
can't find needed dynamic libraries; however, the machine on which
I tested it belongs to someone else who's now gone, and all of my
machines already have GTK installed so I can't easily reproduce the
condition.
In a perfect world, gtk_init_check() would contain enough statically
linked code that it could test for the presence of the GTK libraries
and return an appropriate error if they're absent. But I guess I'll
have to settle for some sort of programmatic test for the existence
of these libraries that won't nuke my program if they're not there.
Is there a way to do this? Can I coax the system to start executing
my program and not insist on the presence of dynamic libraries before
I need them, so I can check whether they're available? And how can I
check whether they're available?
This kind of issue is what dependency tracking in package managers is
for. i.e. you’re trying to solve the problem in completely the wrong
place.
--
http://www.greenend.org.uk/rjk/
Charlie Gibbs
2015-10-01 18:00:00 UTC
Permalink
<snip>
Post by Richard Kettlewell
Can I coax the system to start executing my program and not insist
on the presence of dynamic libraries before I need them, so I can
check whether they're available? And how can I check whether they're
available?
This kind of issue is what dependency tracking in package managers is
for. i.e. you’re trying to solve the problem in completely the wrong
place.
What is the right place? If possible, I'd like to sidestep the whole
"program installation" paradigm and just have a freestanding executable
that can determine its environment and behave appropriately, i.e. run
a limited but usable subset of its full capabilities rather than making
the user chase dependencies.

Have I wandered into DLL hell?
--
/~\ ***@kltpzyxm.invalid (Charlie Gibbs)
\ / I'm really at ac.dekanfrus if you read it the right way.
X Top-posted messages will probably be ignored. See RFC1855.
/ \ HTML will DEFINITELY be ignored. Join the ASCII ribbon campaign!
Richard Kettlewell
2015-10-01 18:36:46 UTC
Permalink
Post by Charlie Gibbs
Post by Richard Kettlewell
Can I coax the system to start executing my program and not insist
on the presence of dynamic libraries before I need them, so I can
check whether they're available? And how can I check whether they're
available?
This kind of issue is what dependency tracking in package managers is
for. i.e. you’re trying to solve the problem in completely the wrong
place.
What is the right place?
As stated above.
Post by Charlie Gibbs
If possible, I'd like to sidestep the whole "program installation"
paradigm and just have a freestanding executable that can determine
its environment and behave appropriately, i.e. run a limited but
usable subset of its full capabilities rather than making the user
chase dependencies.
It you want a GTK+ interface and a non-GTK+ interface, I’d recommend
providing two executables.
--
http://www.greenend.org.uk/rjk/
Charlie Gibbs
2015-10-01 23:39:55 UTC
Permalink
Post by Richard Kettlewell
It you want a GTK+ interface and a non-GTK+ interface, I’d recommend
providing two executables.
Yech. Too much hassle - first for me to distribute, second for users
to try to figure out. My philosophy is to write programs that are
aware of their environment and make the best of it; the less you make
users fiddle with settings, the fewer trouble calls you get. I'd like
to have the program run, although maybe put up a message saying, "If
you'd like it to be _really_ pretty, contact your local IT person and
have him install GTK+-3.0 for you." Unless there's an easy way to
automate that, and the user has Internet access...
--
/~\ ***@kltpzyxm.invalid (Charlie Gibbs)
\ / I'm really at ac.dekanfrus if you read it the right way.
X Top-posted messages will probably be ignored. See RFC1855.
/ \ HTML will DEFINITELY be ignored. Join the ASCII ribbon campaign!
Joe Pfeiffer
2015-10-02 01:27:07 UTC
Permalink
Post by Charlie Gibbs
Post by Richard Kettlewell
It you want a GTK+ interface and a non-GTK+ interface, I’d recommend
providing two executables.
Yech. Too much hassle - first for me to distribute, second for users
to try to figure out. My philosophy is to write programs that are
aware of their environment and make the best of it; the less you make
users fiddle with settings, the fewer trouble calls you get. I'd like
to have the program run, although maybe put up a message saying, "If
you'd like it to be _really_ pretty, contact your local IT person and
have him install GTK+-3.0 for you." Unless there's an easy way to
automate that, and the user has Internet access...
Trying to detect whether gtk is available and then loading it yourself
at runtime is going to be a *lot* more work than the scenario you're
describing above.

If I was dead-set on running without gtk being available on the system,
I'd include a statically linked gtk.
Charlie Gibbs
2015-10-02 16:50:03 UTC
Permalink
Post by Joe Pfeiffer
Trying to detect whether gtk is available and then loading it yourself
at runtime is going to be a *lot* more work than the scenario you're
describing above.
If I was dead-set on running without gtk being available on the system,
I'd include a statically linked gtk.
That'd probably result in one _big_ executable... looks ugly either way.
--
/~\ ***@kltpzyxm.invalid (Charlie Gibbs)
\ / I'm really at ac.dekanfrus if you read it the right way.
X Top-posted messages will probably be ignored. See RFC1855.
/ \ HTML will DEFINITELY be ignored. Join the ASCII ribbon campaign!
Richard Kettlewell
2015-10-02 08:27:03 UTC
Permalink
Post by Charlie Gibbs
Post by Richard Kettlewell
It you want a GTK+ interface and a non-GTK+ interface, I’d recommend
providing two executables.
Yech. Too much hassle - first for me to distribute, second for users
to try to figure out. My philosophy is to write programs that are
aware of their environment and make the best of it; the less you make
users fiddle with settings, the fewer trouble calls you get. I'd like
to have the program run, although maybe put up a message saying, "If
you'd like it to be _really_ pretty, contact your local IT person and
have him install GTK+-3.0 for you." Unless there's an easy way to
automate that, and the user has Internet access...
Linux users with any kind of GUI environment basically all have GTK
installed anyway. You’re proposing to do an absurd amount of work to
optimize for a rather rare case. If that’s really what you want, fair
enough, but the reality is that you’re just doing makework rather than
actually helping anyone else.
--
http://www.greenend.org.uk/rjk/
Charlie Gibbs
2015-10-02 16:50:04 UTC
Permalink
Post by Richard Kettlewell
Linux users with any kind of GUI environment basically all have GTK
installed anyway. You’re proposing to do an absurd amount of work to
optimize for a rather rare case. If that’s really what you want, fair
enough, but the reality is that you’re just doing makework rather than
actually helping anyone else.
Actually, the issue only arose when I tried compiling my program on a Mac.
I agree, it's probably not an issue on most Linux boxes. Maybe it'll be
easier to just specify that Mac users need to install GTK+-3.0 to run it.
(Now I just have to convince my wife that that isn't why her new Mac has
suddenly started locking up and acting strange. I _have_ been hacking
around with it a bit...)
--
/~\ ***@kltpzyxm.invalid (Charlie Gibbs)
\ / I'm really at ac.dekanfrus if you read it the right way.
X Top-posted messages will probably be ignored. See RFC1855.
/ \ HTML will DEFINITELY be ignored. Join the ASCII ribbon campaign!
Jerry Peters
2015-10-01 20:12:32 UTC
Permalink
Post by Charlie Gibbs
I've started learning how to write GTK code. One thing I noticed is
that where gtk_init() will terminate your program if it can't find a
display, gtk_init_check() will tell you whether it succeeded and let
you use other means (e.g. curses or a text-based interface) if not.
I've written a test program that uses this technique, and it works
fine - at least as long as GTK is installed. However, if GTK is
not installed, my program dies instantly. I think it's because it
can't find needed dynamic libraries; however, the machine on which
I tested it belongs to someone else who's now gone, and all of my
machines already have GTK installed so I can't easily reproduce the
condition.
In a perfect world, gtk_init_check() would contain enough statically
linked code that it could test for the presence of the GTK libraries
and return an appropriate error if they're absent. But I guess I'll
have to settle for some sort of programmatic test for the existence
of these libraries that won't nuke my program if they're not there.
Is there a way to do this? Can I coax the system to start executing
my program and not insist on the presence of dynamic libraries before
I need them, so I can check whether they're available? And how can I
check whether they're available?
aTdHvAaNnKcSe for any advice...
Read up on dlopen & friends.
Charlie Gibbs
2015-10-01 23:39:55 UTC
Permalink
<snip>
Post by Jerry Peters
Can I coax the system to start executing my program and not insist on
the presence of dynamic libraries before I need them, so I can check
whether they're available? And how can I check whether they're available?
Read up on dlopen & friends.
Thanks, I'll do that. Better I do the work than the users.
--
/~\ ***@kltpzyxm.invalid (Charlie Gibbs)
\ / I'm really at ac.dekanfrus if you read it the right way.
X Top-posted messages will probably be ignored. See RFC1855.
/ \ HTML will DEFINITELY be ignored. Join the ASCII ribbon campaign!
Jasen Betts
2015-10-02 19:52:15 UTC
Permalink
Post by Charlie Gibbs
<snip>
Post by Jerry Peters
Can I coax the system to start executing my program and not insist on
the presence of dynamic libraries before I need them, so I can check
whether they're available? And how can I check whether they're available?
Read up on dlopen & friends.
Thanks, I'll do that. Better I do the work than the users.
Also look at the source for mtr, it does GTK and non-gtk with a single
binary.

http://www.bitwizard.nl/mtr/
--
\_(ツ)_
Charlie Gibbs
2015-10-02 20:13:58 UTC
Permalink
Post by Jasen Betts
Post by Charlie Gibbs
<snip>
Post by Jerry Peters
Can I coax the system to start executing my program and not insist on
the presence of dynamic libraries before I need them, so I can check
whether they're available? And how can I check whether they're available?
Read up on dlopen & friends.
Thanks, I'll do that. Better I do the work than the users.
Also look at the source for mtr, it does GTK and non-gtk with a single
binary.
http://www.bitwizard.nl/mtr/
Thanks. Will do.
--
/~\ ***@kltpzyxm.invalid (Charlie Gibbs)
\ / I'm really at ac.dekanfrus if you read it the right way.
X Top-posted messages will probably be ignored. See RFC1855.
/ \ HTML will DEFINITELY be ignored. Join the ASCII ribbon campaign!
Jerry Peters
2015-10-02 20:08:18 UTC
Permalink
Post by Charlie Gibbs
<snip>
Post by Jerry Peters
Can I coax the system to start executing my program and not insist on
the presence of dynamic libraries before I need them, so I can check
whether they're available? And how can I check whether they're available?
Read up on dlopen & friends.
Thanks, I'll do that. Better I do the work than the users.
It looks like a PITA though, I like one of the other suggestions: have
2 programs, one GTK, the other not and invoke them with a simple
wrapper script. Something like:

#!/bin/sh
gtk-program "$@" ||
other-program "$@"

If you segregate the UI from the rest of the logic both programs could
be built from the same code base by linking with a different UI
interface module.
Jasen Betts
2015-10-02 19:38:11 UTC
Permalink
Post by Charlie Gibbs
I've started learning how to write GTK code. One thing I noticed is
that where gtk_init() will terminate your program if it can't find a
display, gtk_init_check() will tell you whether it succeeded and let
you use other means (e.g. curses or a text-based interface) if not.
I've written a test program that uses this technique, and it works
fine - at least as long as GTK is installed. However, if GTK is
not installed, my program dies instantly.
No, it doesn't. If there's no GTK /bin/ld.so doesn't even start it.
Post by Charlie Gibbs
I think it's because it
can't find needed dynamic libraries; however, the machine on which
I tested it belongs to someone else who's now gone, and all of my
machines already have GTK installed so I can't easily reproduce the
condition.
create a chroot environment. or a virtual mchine.
Post by Charlie Gibbs
In a perfect world, gtk_init_check() would contain enough statically
linked code that it could test for the presence of the GTK libraries
and return an appropriate error if they're absent.
ld.so checks for the shared libraries before starting your code.
Post by Charlie Gibbs
But I guess I'll
have to settle for some sort of programmatic test for the existence
of these libraries that won't nuke my program if they're not there.
yeah, this means you can't link them dynamically, you'll have to do runtime
linking (eg. using dlopen)
--
\_(ツ)_
Loading...