f



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

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!
0
Charlie
10/1/2015 6:43:40 AM
comp.os.linux.development.apps 5216 articles. 1 followers. Post Follow

14 Replies
514 Views

Similar Articles

[PageSpeed] 52

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/
0
Richard
10/1/2015 8:30:10 AM
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!
0
Charlie
10/1/2015 6:00:00 PM
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/
0
Richard
10/1/2015 6:36:46 PM
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.
0
Jerry
10/1/2015 8:12:32 PM
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!
0
Charlie
10/1/2015 11:39:55 PM
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!
0
Charlie
10/1/2015 11:39:55 PM
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/
0
Richard
10/2/2015 1:01:01 AM
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.
0
Joe
10/2/2015 1:27:07 AM
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!
0
Charlie
10/2/2015 4:50:03 PM
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!
0
Charlie
10/2/2015 4:50:04 PM
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)


-- 
  \_(ツ)_
0
Jasen
10/2/2015 7:38:11 PM
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/


-- 
  \_(ツ)_
0
Jasen
10/2/2015 7:52:15 PM
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.
0
Jerry
10/2/2015 8:08:18 PM
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!
0
Charlie
10/2/2015 8:13:58 PM
Reply:

Similar Artilces:

os.linux.development.apps
hEy, Please Visit http://www.familypk.com Familypk About Articles, Tutorials, Learning, Block checkers, Myspace, Twist, Daily news updates, Entertainment, Horoscopes, Movies, Stories, Kids, Woman, Kitchen, Islamic names, Hair style, Fashion, Home decoration, Songs, PTCL, Games, etc..... Please Visit http://www.enttwist.com Enttwist About Articles, Tutorials, Cheat Codes, Hacking News, Games Setup, Greeting Cards, E-Cards, Telephone Directry, Web Directry, Learning, Block checkers, Myspace, Twist, Daily news updates, Entertainment, Horoscopes, Movies, ...

Developing old Mac OS apps on Linux?
Does anybody know if it is possible to develop apps that run on the old Mac OS (6,7,8,9) using Linux development tools? I know that it is possible to set up a gnu toolchain to cross-compile and link apps for the m68k target. What I'm looking for is a small glue layer (SDK) that I would allow my apps to run under Mac OS. I haven't investigated this much, so I'm not sure what is out there. I know this sounds obscure, but I want to develop a few applications to run on an old powerbook running Mac OS 7. I don't think it is possible to get the old development tools fro...

Somebody please PLEASE tell me how to install Linux on Windows (oh the pain, the PAIN of Linux installs!)
In another thread (http://tinyurl.com/2us2ep) I got no real help on how to install Linux onto a SATA drive, though I idid learn some trivia about AMD chips. But when attempting to install Linux Mandriva (see the above thread) I noticed that Mandriva only ran off the hard drive. It was akin to a demo rather than a real OS. It did look nice, I'll grant you that. For a minute, as a Microsoft shareholder, I was briefly worried that maybe there was something to this Linux movement after all. For a minute. Now can anybody please point me to a site or otherwise tell me how to go about insta...

What tools should I choose to develop app/sys program in Linux OS?
Hello, Everybody, I am a newbie for Linux. I want to develop the application/system programs in Linux Os. And I am using the Red Hat 7.2 Linux.The languages that I will use are ASM ,C and C++. Pls tell me , what tool(or tools) should I choose ? Thanks in advance! George. 2003-06-26 In article <bdf4or$2its$1@mail.cn99.com>, George Zhang wrote: > Hello, Everybody, > > I am a newbie for Linux. I want to develop the application/system programs Hint: Around here, "system" refers to the kernel. If you're doing kernel work, fine. Oth...

[News] GNU/Linux Program Installation Moved Beyond OS X and Windows
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Package Management - Avoiding the Two Step ,----[ Quote ] | See, the beauty is that even though things like apt-get and synaptic make | installing programs as easy as double clicking on setup.exe -- the difference | is that we have a choice as to whether or not we pick the convenience of | package management. It's the freedom to choose that makes Linux and open | source so great. `---- http://www.linuxjournal.com/content/package-management-avoiding-two-step Related: Get down and dirty with Linux ,----[ Quote ] | Package managers ...

Installing OS X apps over OS 9 versions
Having upgraded an iMac DV to the latest OS 9 and firmware versions, I'm now ready to install OS X, and then OS X versions of AppleWorks and Eudora. But a question has occurred to me: Will the OS X app versions install into the same directories as their OS 9 counterparts, and overwrite those counterparts? If so, what happens if I decided to boot the iMac into OS 9? Ideally it seems that if I am running OS X and I click on an AppleWorks document then the OS X version of AppleWorks should come up, while if I have booted into OS 9 and click on the same document then the older OS 9 version...

[News] Linux Wins Because of Applications (Developers, Developers, Developers Come to Linux)
Red Hat growth: A tale of 2,000 applications ,----[ Quote ] | Red Hat's Linux business continues to boom, even when we don't give it the | credit that it deserves. What is the underlying reason for that growth? | | Applications. `---- http://blogs.cnet.com/8301-13505_1-9791171-16.html?part=rss&tag=feed&subj=TheOpenRoad Open Source for Business: Now More Than Ever, Part 1 ,----[ Quote ] | No App Scarcity | | The growth of open source applications in the business workplace, at least to | some degree, is the result of a large inventory of program choices. There is | no s...

[News] [Linux] Linux Goes Beyond x86, Attracts Developers
Power Architecture, Part 2: Drawing In Developers ,----[ Quote ] | While IBM dominates HPC, and Freescale owns much of the embedded market, | the middle desktop is missing from the Power Architecture landscape. Power | continues to thrive without the desktop space, but the desktop does, in | fact, unify an ecosystem and provide a consumer face. | | [...] | | The Consortium | provides access to high-performance Linux OS systems with an | immediate focus on the Cell Broadband Engine found in the IBM | and Mercury Cell products, and the Cell processor found in the | Sony PlayStation 3. `---- ...

The Linux desktop experience is killing Linux on the desktop. A VLC Developer Tells The Truth.....
Here we have the lead developer for VLC telling the truth about the sorry state of Linux. See how many items he mentions (Pulseaudio, KDE4.x etc) that SUCK for everyone BUT the LIARS IN COLA. For the COLA herd everything Linux "just works". That's because they LIE for LIEnux. So who are we to believe? A person deeply involved with Linux who admits that desktop Linux has some serious problems, or the do nothing COLA herd who claim it all "just works" and it's the user's fault. Get ready for the herd to mobilize and attempt to discredit the author of these com...

[News] Video Proves That Linux Installation Easier Than OS X, Vista Installation
Installation on Vista, OSX, and Ubuntu ,----[ Quote ] | Shows software installation (Mozilla Thunderbird) on Vista, OSX, | and Ubuntu. `---- http://youtube.com/watch?v=xA7cP-qpdlI Very recent items that support this: Free Agent: How to Compile Free Software Apps ,----[ Quote ] | Let me start with a controversial statement: Installing | new software is almost always easier on Linux than on | Windows or the Mac OS. | | I can already envision the angry e-mail. It'll come from | the folks who write each month, certain that if they use | enough capital letters and exclamation points, they&...

Which Linux OS should I install
I am very very new to Linux. I have a very old laptop that I am experimenting with. I am trying to run it as an image viewer. Something that will scroll pictures from a directory. So I thought here would be a perfect time to play with Linux. I've gone to a Linux distros site, but there are so many. I searched for a minimalist Linux version and burned a couple iso's, but I couldn't get any of them to work. Can any of you recommend a version that would do what I want it to do? My skill level is quite amateurish. Thanks Jeff P.S. I formatted the drive so there is currently no OS. I...

save all settings (desktop, modem/isp, mail, installed apps, "Linux base-installation" )
Hi, I am new to Linux(at the moment i am experimenting with Knoppix) Is there a way to save all settings (desktop, modem/isp, mail, installed apps, "Linux base-installation") ? The purpose of that procedure is that after restoring the known-good baseline hd-image(e.g. taken after the installation of Linux), i would like to be able to "restore/apply" these "system-changes" without the need to configure the system manually. Or are there better approaches? Cheers, John linux55@bluemail.ch (john) wrote in message news:<52d95eb6.0311100129.33fcbd8e@postin...

SN#18864 Sun Installation Assistant Easily Installs Linux, Windows OS on Sun x64 Servers
SYSTEM NEWS FOR SUN USERS Vol 116 Issue 5 2007-10-29 Article 18864 from section "SysAdmin's Section" How-To Guide Demonstrates in Just 12 Steps Installing supported Linux and Windows onto Sun x64 servers is easy with the Sun Installation Assistant (SIA). Just boot from the SIA CD or a local network copy of SIA, then choose the required OS from the list in the graphical menu and follow the installation instructions. The Sun SIA team has posted a brief how-to guide on using the installation tool so viewers can see just how effor...

starting a gtk+ app from inside another gtk+ app
I did a fork and an execve, but the newly started app says: Gtk-WARNING **: Cannot open display: Various things are carried over from the original process to the new process, so after the fork, but before the execve, I assume there's some clean-up I need to do, like closing the display and maybe undoing other effects of the gtk_init in the originating app... Anybody have any example code? Thanks, Bill William Winkler wrote: > > I did a fork and an execve, but the newly started app says: > > Gtk-WARNING **: Cannot open display: > > Various...

Web resources about - Beyond gtk_init_check() - how do I tell if GTK is installed? - comp.os.linux.development.apps

Resources last updated: 1/25/2016 4:31:12 AM