LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Expanding my C usage. (https://www.linuxquestions.org/questions/programming-9/expanding-my-c-usage-4175721855/)

jmgibson1981 02-09-2023 03:40 PM

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
Code:

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

NevemTeve 02-09-2023 03:59 PM

Try to describe the desired functionality and ask google. E.g.:https://www.google.com/search?q=C+find+string+in+string

EdGr 02-09-2023 05:34 PM

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

jmgibson1981 02-09-2023 08:35 PM

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.

chrism01 02-09-2023 09:47 PM

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.

jmgibson1981 02-09-2023 10:01 PM

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.

NevemTeve 02-10-2023 12:09 AM

One could learn a lot from `info libc` (or `tkinfo libc` in GUI).

hazel 02-10-2023 05:01 AM

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

sundialsvcs 02-12-2023 05:12 PM

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.

rtmistler 02-12-2023 06:36 PM

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:
  1. First thing is it tells you what library, a.k.a. include file(s) you need to use for it
  2. Next it tells you about that function, how to call it, the arguments for it, and the expected return of it
  3. 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.

sundialsvcs 02-13-2023 08:15 AM

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.

NevemTeve 02-13-2023 08:43 AM

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

chrism01 02-13-2023 10:58 PM

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/

astrogeek 02-14-2023 12:11 AM

Quote:

Originally Posted by NevemTeve (Post 6410987)
I thought it was just me, but just now I've found this: http://harmful.cat-v.org/software/dy...sioned-symbols

Thank you very much for ruining my day! I was blissfully unaware of any of that...

jmgibson1981 02-14-2023 07:51 AM

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 05:46 AM.