Recent

Author Topic: What libraries are used and who specifies them?  (Read 2083 times)

jollytall

  • Sr. Member
  • ****
  • Posts: 376
What libraries are used and who specifies them?
« on: June 21, 2019, 06:20:47 pm »
I use Debian 9, Gnome 3.22.2, Lazarus 2.0.0RC3, FPC 3.0.4 on 64bits.

I have a concrete problem with MySQL library linking (I asked it in the relevant group), but I would like to understand it more in general as well. What I see in my example is that my program is using an .so library. I can get it listed, when my program is running through the lsof linux command.
What I would like to see in development time (in some sort of linker log, or alike), what libraries will be used by my program and where they are specified (which unit). Is there such a place?

Thanks,

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: What libraries are used and who specifies them?
« Reply #1 on: June 22, 2019, 12:14:46 am »
To see on what libraries depends your binary you can call ldd as a post-compile command (or add it as an External Tool).

As for how to see where they are specified ... no idea, other than grepping the sources for the names given by ldd

Not much help, is it? Sorry. :-[
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

zoltanleo

  • Hero Member
  • *****
  • Posts: 509
Re: What libraries are used and who specifies them?
« Reply #2 on: June 22, 2019, 12:49:01 am »
I have a concrete problem with MySQL library linking (I asked it in the relevant group)
I do not quite understand your question. Want to know which libraries use your access components? Or do you want to know where to look for these libraries? What exactly?
Win10 LTSC x64/Deb 12 amd64(gtk2)/Kubuntu(qt5)/Darwin Cocoa x86_64 (Sequoia):
Lazarus x32_64 (trunk); FPC(trunk), FireBird 3.0.11; IBX by TonyW

Sorry for my bad English, I'm using translator ;)

jollytall

  • Sr. Member
  • ****
  • Posts: 376
Re: What libraries are used and who specifies them?
« Reply #3 on: June 22, 2019, 08:43:04 am »
To see on what libraries depends your binary you can call ldd as a post-compile command (or add it as an External Tool).

As for how to see where they are specified ... no idea, other than grepping the sources for the names given by ldd

Not much help, is it? Sorry. :-[

Thanks, but this did not help. When I use ldd, I do not get all libraries:-(. When I start my program and use lsof, I do not get them either. The reason can be that my mysql is only connected when I need it.
If I run lsof when sql is connected, I see more libraries in lsof than those I see when the program is idle. I specifically get the following entries:
  mem       REG                8,2    47632  9176675 /lib/x86_64-linux-gnu/libnss_files-2.24.so
  mem       REG                8,2    92584  9175044 /lib/x86_64-linux-gnu/libgcc_s.so.1
  mem       REG                8,2  4179432 10631843 /usr/lib/x86_64-linux-gnu/libmariadbclient.so.18.0.0
  mem       REG                8,2  1566168 10622268 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22
These four do not appear in ldd, or lsof when idle. The problem is that libmariadbclient.so is not thread safe, and I would need to change it to libmariadbclient_r.so what apparently is.
"grep" to find the reference can also be tricky, especially if it is referenced in a binary.

I have a concrete problem with MySQL library linking (I asked it in the relevant group)
I do not quite understand your question. Want to know which libraries use your access components? Or do you want to know where to look for these libraries? What exactly?
Thanks, but none of the two. I can find what libraries are used (see above), and I can also find them on the disk (lsof gives that too). What I do not find, which unit specifies it, and how I could change it.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: What libraries are used and who specifies them?
« Reply #4 on: June 22, 2019, 09:51:02 am »
I may be wrong but those libraries you see are probably loaded from the MySQL client lib. That is, they are not a dependency of your program but of MySQL (or, rather, MariaDB?).

It's dificult, sometimes, to follow this chain of dependencies.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

jollytall

  • Sr. Member
  • ****
  • Posts: 376
Re: What libraries are used and who specifies them?
« Reply #5 on: June 22, 2019, 04:53:34 pm »
Those surely are somehow linked to MySQL as they only appear when there is an acitve connection. Nonetheless, they are needed for my program to run. They appear under my program's ID in lsof.

I am also fine if it has to be changed in a MySQL config somewhere, but I have no clue where. Any idea?

***

back to the original problem as well: If I find a library used, listed in ldd, how can I find which unit is referring to it?

Thanks,

PascalDragon

  • Hero Member
  • *****
  • Posts: 6035
  • Compiler Developer
Re: What libraries are used and who specifies them?
« Reply #6 on: June 22, 2019, 05:32:59 pm »
Those surely are somehow linked to MySQL as they only appear when there is an acitve connection. Nonetheless, they are needed for my program to run. They appear under my program's ID in lsof.

I am also fine if it has to be changed in a MySQL config somewhere, but I have no clue where. Any idea?
This isn't something that can be simply changed by some configuration. These libraries are simply needed by the library. The libstdc++ is essentially what the RTL is for FPC and libgcc is some lowlevel routines. And libnss is required for cryptography. There is no way around this as they're essential.

back to the original problem as well: If I find a library used, listed in ldd, how can I find which unit is referring to it?
You can't this way.

What you can do however is run the ppudump utility that is provided with your FPC release on each and every PPU and filter for "External Library" and then check whether you can find the libraries listed by ldd there. This however won't cover libraries that are loaded dynamically using LoadLibrary and friends (for those you'd need to search the unit's sources for LoadLibrary which can of course become more complicated if there should be some wrapper or abstraction involved for whatever reason).

jollytall

  • Sr. Member
  • ****
  • Posts: 376
Re: What libraries are used and who specifies them?
« Reply #7 on: June 22, 2019, 06:28:20 pm »
Thanks.
I know that those are needed, but from the MySQL libraries there are the ones that are non thread safe (e.g. libmariadbclient.so) and the same with thread safe set-up (libmariadbclient_r.so). What I try to achieve somehow is to use the thread safe version.
I found this post: https://forum.lazarus.freepascal.org/index.php/topic,22723.msg134501.html#msg134501, saying to override the library name, but still do not know how.

PascalDragon

  • Hero Member
  • *****
  • Posts: 6035
  • Compiler Developer
Re: What libraries are used and who specifies them?
« Reply #8 on: June 22, 2019, 07:24:09 pm »
You'll need to manually call InitialiseMySQL from the correct MySQLXDyn unit with your desired library name at the start of your program and ReleaseMySQL when your program terminates.

jollytall

  • Sr. Member
  • ****
  • Posts: 376
Re: What libraries are used and who specifies them?
« Reply #9 on: June 22, 2019, 07:51:41 pm »
Thanks a lot. I do not say I understand what I do exactly  :(, but it did the trick  :D.

Thanks again.

 

TinyPortal © 2005-2018