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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
02-09-2023, 03:40 PM
|
#1
|
Senior Member
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,185
|
Expanding my C usage.
I'm stuck on libraries. I know there are countless libraries out there. I know they contain functions that can be dynamically linked to to utilize them and not reinvent the wheel. I know how to get some output from None of this helps me to know how am I supposed to find the proper libary for a given thing I'm doing, if it exists. Is there no other way than looking at git pages or something directly at the code? In which case is it sheer dumb luck stumbling on the proper library i'm looking for?
Google is zero help. Countless results on how to link to libraries, where they are, how they work (to a degree) but I have found nada on how to search libraries overall to find if the function i need already exists somewhere. And in which library it exists.
|
|
|
02-09-2023, 03:59 PM
|
#2
|
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,924
|
Try to describe the desired functionality and ask google. E.g.: https://www.google.com/search?q=C+find+string+in+string
|
|
1 members found this post helpful.
|
02-09-2023, 05:34 PM
|
#3
|
Senior Member
Registered: Dec 2010
Location: California, USA
Distribution: I run my own OS
Posts: 1,015
|
jmgibson - Your distro has made finding library functions difficult by not installing headers or documentation by default. Install them for the libraries that you are interested in.
Ed
|
|
1 members found this post helpful.
|
02-09-2023, 08:35 PM
|
#4
|
Senior Member
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,185
Original Poster
|
I think you misunderstand. I don't know which libraries I would want. I can man page them but is there NY quick way to narrow that down. There seems to be no central place t9 search for given functions
*EDIT 5 mins later *
Unless I can search via apropos and that will get me started... thank you for the insight. Maybe not what I wanted but got me thinking about the man pages again.
Last edited by jmgibson1981; 02-09-2023 at 08:37 PM.
|
|
|
02-09-2023, 09:47 PM
|
#5
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,393
|
apropos searches the man pages ok, but if you install the assoc headers src files and docs, you can grep through those...
Could be quicker.
Also, if you ls the dirs those are in, you can often just spot the most likely candidate from the name eg 'math.h' is the first place to look for maths fns etc.
|
|
1 members found this post helpful.
|
02-09-2023, 10:01 PM
|
#6
|
Senior Member
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,185
Original Poster
|
Okay thank you. That helps a great deal. I supposed it would be damn near impossible to create a searchable db of all the libs out there. But all 3 of you have helped. With the idea to look by general type I can just apt search (or whatever a given distro does) to find generally what I'm looking for. In the case of Debian + derivatives I can just apt source the dev pkg and dig through it.
Thank you all very much. Long way to go but loving every minute of it... even with the occasional frustrations.
|
|
|
02-10-2023, 12:09 AM
|
#7
|
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,924
|
One could learn a lot from `info libc` (or `tkinfo libc` in GUI).
|
|
|
02-10-2023, 05:01 AM
|
#8
|
LQ Guru
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,869
|
You could try skimming through Linux From Scratch and Beyond Linux From Scratch. The BLFS contents list would be particularly useful for this kind of thing as it has the software organised by type, e.g.security, graphics, networking...
|
|
|
02-12-2023, 05:12 PM
|
#9
|
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,827
|
The choice of libraries is simply a "design choice" that you must somehow make while creating your application. While there are sometimes multiple choices, in most cases just a few have become "reliable, cross-platform, 'industry standards.'"
Each library comes with both binaries and a set of header files to describe its use.
"But Also!! ... ... Always remember the admonition to "do not do a thing already done!" You will usually be able to find some software package which "insulates you" from having to interact with your chosen library directly. These libraries will "abstract away" at least some of the messy details of "using a binary library correctly."
It is today a very reliable "rule of thumb" to presume(!) that whatever-it-is you are trying to do is: "a thing already done." Always think outside the box and do not write any more "original source code" than you have to.
As Perl programmers like to say: "Tim Toady" = TMTOWTDI = There's More Than One Way To Do It." For instance, if you need to process an XML file, there are already-perfected "Pure Perl" libraries that will do that. But the usual way to do that is to use binary libraries – "libxml2" or "SAX." And the Perl language provides already-perfected "wrappers" for both which let you completely ignore how it is all done. Other languages which appear to "build in" support for XML use these libraries behind the scenes. No matter what is the language, somewhere you will find a good "wrapper" to do the dirty work for you.
Last edited by sundialsvcs; 02-13-2023 at 08:12 AM.
|
|
|
02-12-2023, 06:36 PM
|
#10
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,892
|
Maybe you just haven't organized your ways to look things up.
Example search for "strstr manpage"
You find manpages for strstr.
But read those: - First thing is it tells you what library, a.k.a. include file(s) you need to use for it
- Next it tells you about that function, how to call it, the arguments for it, and the expected return of it
- Next there's usually a "See Also" section where is show related functions
Virtually all C library functions have a man page and additional information about them.
There's no right answer, learn what benefits you and your most recent efforts.
|
|
|
02-13-2023, 08:15 AM
|
#11
|
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,827
|
FYI: Virtually every program written in any compiled language is created to make extensive calls to a usually-dynamic "runtime library." For Linux "C" that library is glibc. In a Microsoft environment it is MSVCRTxx.DLL. While it is usually possible to "static-link" a program so that it has no runtime dependencies at all, this is almost never done. When a dynamic library is loaded by one process, its virtual-memory resources are shared by all of them, greatly reducing the memory footprint.
|
|
|
02-13-2023, 08:43 AM
|
#12
|
Senior Member
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,924
|
Mind you, the nowadays trendy versioned symbols present a very good reason to link statically. (Sure, they are meant to solve compatibility problems. By causing more serious compatibility problems. Clever.)
Edit: I thought it was just me, but just now I've found this: http://harmful.cat-v.org/software/dy...sioned-symbols
Last edited by NevemTeve; 02-13-2023 at 08:44 AM.
|
|
1 members found this post helpful.
|
02-13-2023, 10:58 PM
|
#13
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,393
|
Your own system is the definitive info for what's on it, but this is handy for a quick search and easier on the eyes (imho) https://linux.die.net/man/
|
|
|
02-14-2023, 12:11 AM
|
#14
|
Moderator
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,295
|
Quote:
Originally Posted by NevemTeve
|
Thank you very much for ruining my day! I was blissfully unaware of any of that...
|
|
1 members found this post helpful.
|
02-14-2023, 07:51 AM
|
#15
|
Senior Member
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,185
Original Poster
|
I am grateful to all of you for your suggestions. It definitely helps. Thank you all.
|
|
|
All times are GMT -5. The time now is 03:57 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|