LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-02-2011, 05:09 PM   #1
KillerCode
Member
 
Registered: Nov 2010
Posts: 57

Rep: Reputation: 0
Application Fails if Lib not found, anyway to avoid this?


i was wondering if there is away to avoid application from closing if a specific library not found?

for example: if my application uses libPng and it wasn't found on the system running my app (binary and not source), is there anyway to just disable the part that uses png from my application?

thanks;
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 01-02-2011, 05:12 PM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
It is kind of hard for us to tell you what libraries your application does or does not need. If your application doesn't need libpng, then don't link against it. If your code requires the functionality of libpng, then there isn't much you can do about it.
 
Old 01-02-2011, 05:17 PM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by MS3FGX View Post
It is kind of hard for us to tell you what libraries your application does or does not need. If your application doesn't need libpng, then don't link against it. If your code requires the functionality of libpng, then there isn't much you can do about it.
Well, not quite. If the application can deal with other than PNG formats, and if the application is using dynamic libraries ( .so files under Linux), the the application can check library existence before using its functions:

man 3 dlopen

and friends, also look up

GNU libtool

which has convenient cross-platform wrappers and somewhat abstracts out linking.
 
2 members found this post helpful.
Old 01-02-2011, 05:25 PM   #4
KillerCode
Member
 
Registered: Nov 2010
Posts: 57

Original Poster
Rep: Reputation: 0
@MS3FGX: i know what libraries it uses, but the problem is, if those libraries arent found on user pc the whole application wont start, im looking for away so it starts and just disable the part that uses this library

@Sergei Steshenko: are those dlopen and dlsym are like windows LoadLibrary and GetProcAddress? (Load a library and get its handle, and then find procedure addresses through this handle?
 
Old 01-02-2011, 05:40 PM   #5
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,223

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
There is in Python. In Python, you get an exception if a given library is not found. You can catch the exception and branch as appropriate.

Linux C/C++ programs resolve this at compile-time, using GNU Autotools. Or, you can link libpng statically.

Last edited by dugan; 01-02-2011 at 05:48 PM.
 
Old 01-02-2011, 06:01 PM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by KillerCode View Post
...
@Sergei Steshenko: are those dlopen and dlsym are like windows LoadLibrary and GetProcAddress? (Load a library and get its handle, and then find procedure addresses through this handle?
I don't know Windows programming; 'libtool' abstracts the details out, i.e. your code looks the same for both Windows and UNIXish systems, I think that even library file names can be forced to look the same rather than to have .so or .dll extensions.
 
Old 01-02-2011, 06:03 PM   #7
KillerCode
Member
 
Registered: Nov 2010
Posts: 57

Original Poster
Rep: Reputation: 0
im gonna try now
thx all for the great help
 
Old 01-07-2011, 01:02 AM   #8
KillerCode
Member
 
Registered: Nov 2010
Posts: 57

Original Poster
Rep: Reputation: 0
i know its kinda late to post results, but, actually dlopen, dlsym, dlerror and all those require a library too :/ -ldl have to link dl library to that

is there anyway to avoid that? cause if it's not found, my app will still fail :S
 
Old 01-07-2011, 01:55 AM   #9
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Try linking your essential libraries statically.
 
Old 01-07-2011, 05:43 AM   #10
KillerCode
Member
 
Registered: Nov 2010
Posts: 57

Original Poster
Rep: Reputation: 0
is that different from -l command under gcc?
 
Old 01-07-2011, 06:21 AM   #11
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
you might want to google gcc linker options and look up the -static switch
 
Old 01-07-2011, 06:22 AM   #12
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by KillerCode View Post
is that different from -l command under gcc?
I don't know what "-l command under gcc" means. As far as I know, gcc does not have a -l option. But graemef is referring to the -static option under gcc.
 
Old 01-07-2011, 06:33 AM   #13
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by wje_lq View Post
I don't know what "-l command under gcc" means. As far as I know, gcc does not have a -l option.
The option -llibrary will link the library named library but the default is to do it dynamically, if possible.

linker options
 
Old 01-07-2011, 07:49 AM   #14
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by graemef View Post
The option -llibrary will link the library named library
D'oh! I knew that! :(
 
Old 01-07-2011, 09:54 AM   #15
KillerCode
Member
 
Registered: Nov 2010
Posts: 57

Original Poster
Rep: Reputation: 0
Code:
-static
On systems that support dynamic linking, this prevents linking with the shared libraries. On other systems, this option has no effect.
i still got no idea what that means?? does it mean that the library will be part of my application? both will be 1 file?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
GCC fails to compile - Chapter 6.14 - C preprocessor "/lib/cpp" fails sanity check jaydoc Linux From Scratch 1 01-28-2009 05:17 PM
configure script fails with: SDL_image lib not found! slackermax Fedora 1 10-16-2008 03:48 PM
Application needs lib file mickeyboa Fedora 1 11-30-2005 12:19 AM
gcc vs. g++ -> iostream lib found vs. not found CooManChu Linux - General 1 12-11-2004 09:20 AM
How can we use lib*.so file with application satishpatel Linux - Software 1 05-02-2004 07:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration