Runtime location of a Function by name in a string

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Runtime location of a Function by name in a string

Post by TJF »

Xusinboy Bekchanov wrote:How can we get dynamic libraries to work in Linux like in Windows?
That doesn't make sense. Try to get them working like in LINUX. Find a cross platform solution (workaround) in post

https://freebasic.net/forum/viewtopic.php?f=27&t=29411&start=15#p285797
Xusinboy Bekchanov
Posts: 782
Joined: Jul 26, 2018 18:28

Re: Runtime location of a Function by name in a string

Post by Xusinboy Bekchanov »

And it is normal that you do not know what is inside the dll, but when you call dll, does the dll call a randomly matching function or type from the main program?
marcov
Posts: 3454
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Runtime location of a Function by name in a string

Post by marcov »

As far as I know it (and I write this from memory to give a general picture, research for details)

On Linux, all symbols are in a single linker namespace (symbol table), binary and library.

On windows, but also commercial Unixes like OS X, every module (binary or library) has its own linker namespace. IOW to find a symbol you must always pass something identifying the module (dll/.so/.dyliblibrary) as well as the symbol name.

When _statically_ linking a dynamic library, an import lib is generated that has something like this

_stat:
jmp $0 // this value is relocated by the loader with the address of the function in the DLL
some info or references to a table here, so that the dyn linker can find symbol name etc.

in this case you cal _stat


When dynamically linking, the DLL is loaded into your process space, and you must use dlsym/getprocaddress to get a pointer to the code. Note that getprocaddress has two arguments, module handle and symbol name

p.s. good reading: the free "Linkers and Loaders" book from John Irvine
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Runtime location of a Function by name in a string

Post by TJF »

Xusinboy Bekchanov wrote:And it is normal that you do not know what is inside the dll, but when you call dll, does the dll call a randomly matching function or type from the main program?
All you need to know are the API entry points. Those should get DECLAREd in the header file, which gets #INCLUDEd by both, the main code and the library code.
Post Reply