• Beyond gtk_init_check() - how do I tell if GTK is installed?

    From Charlie Gibbs@21:1/5 to All on Thu Oct 1 06:43:40 2015
    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...

    --
    /~\ cgibbs@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!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Kettlewell@21:1/5 to Charlie Gibbs on Thu Oct 1 09:30:10 2015
    Charlie Gibbs <cgibbs@kltpzyxm.invalid> writes:
    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/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Charlie Gibbs@21:1/5 to Richard Kettlewell on Thu Oct 1 18:00:00 2015
    On 2015-10-01, Richard Kettlewell <rjk@greenend.org.uk> wrote:

    Charlie Gibbs <cgibbs@kltpzyxm.invalid> writes:

    <snip>

    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?

    --
    /~\ cgibbs@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!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Kettlewell@21:1/5 to Charlie Gibbs on Thu Oct 1 19:36:46 2015
    Charlie Gibbs <cgibbs@kltpzyxm.invalid> writes:
    Richard Kettlewell <rjk@greenend.org.uk> wrote:
    Charlie Gibbs <cgibbs@kltpzyxm.invalid> writes:
    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.

    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/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jerry Peters@21:1/5 to Charlie Gibbs on Thu Oct 1 20:12:32 2015
    Charlie Gibbs <cgibbs@kltpzyxm.invalid> wrote:
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Joe Pfeiffer@21:1/5 to Charlie Gibbs on Thu Oct 1 19:27:07 2015
    Charlie Gibbs <cgibbs@kltpzyxm.invalid> writes:

    On 2015-10-01, Richard Kettlewell <rjk@greenend.org.uk> wrote:

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Charlie Gibbs@21:1/5 to Jerry Peters on Thu Oct 1 23:39:55 2015
    On 2015-10-01, Jerry Peters <jerry@example.invalid> wrote:

    Charlie Gibbs <cgibbs@kltpzyxm.invalid> wrote:

    <snip>

    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.

    --
    /~\ cgibbs@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!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Charlie Gibbs@21:1/5 to Richard Kettlewell on Thu Oct 1 23:39:55 2015
    On 2015-10-01, Richard Kettlewell <rjk@greenend.org.uk> wrote:

    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...

    --
    /~\ cgibbs@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!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Kettlewell@21:1/5 to Charlie Gibbs on Fri Oct 2 09:27:03 2015
    Charlie Gibbs <cgibbs@kltpzyxm.invalid> writes:
    Richard Kettlewell <rjk@greenend.org.uk> wrote:

    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/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Charlie Gibbs@21:1/5 to Joe Pfeiffer on Fri Oct 2 16:50:03 2015
    On 2015-10-02, Joe Pfeiffer <pfeiffer@cs.nmsu.edu> wrote:

    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.

    --
    /~\ cgibbs@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!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Charlie Gibbs@21:1/5 to Richard Kettlewell on Fri Oct 2 16:50:04 2015
    On 2015-10-02, Richard Kettlewell <rjk@greenend.org.uk> wrote:

    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...)

    --
    /~\ cgibbs@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!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jasen Betts@21:1/5 to Charlie Gibbs on Fri Oct 2 19:52:15 2015
    On 2015-10-01, Charlie Gibbs <cgibbs@kltpzyxm.invalid> wrote:
    On 2015-10-01, Jerry Peters <jerry@example.invalid> wrote:

    Charlie Gibbs <cgibbs@kltpzyxm.invalid> wrote:

    <snip>

    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/


    --
    \_(ツ)_

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jasen Betts@21:1/5 to Charlie Gibbs on Fri Oct 2 19:38:11 2015
    On 2015-10-01, Charlie Gibbs <cgibbs@kltpzyxm.invalid> wrote:
    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.

    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.

    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.

    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)


    --
    \_(ツ)_

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jerry Peters@21:1/5 to Charlie Gibbs on Fri Oct 2 20:08:18 2015
    Charlie Gibbs <cgibbs@kltpzyxm.invalid> wrote:
    On 2015-10-01, Jerry Peters <jerry@example.invalid> wrote:

    Charlie Gibbs <cgibbs@kltpzyxm.invalid> wrote:

    <snip>

    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Charlie Gibbs@21:1/5 to Jasen Betts on Fri Oct 2 20:13:58 2015
    On 2015-10-02, Jasen Betts <jasen@xnet.co.nz> wrote:

    On 2015-10-01, Charlie Gibbs <cgibbs@kltpzyxm.invalid> wrote:

    On 2015-10-01, Jerry Peters <jerry@example.invalid> wrote:

    Charlie Gibbs <cgibbs@kltpzyxm.invalid> wrote:

    <snip>

    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.

    --
    /~\ cgibbs@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!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)