Recent

Author Topic: Share libraries: dl.dll not found  (Read 197 times)

Borneq

  • Full Member
  • ***
  • Posts: 213
Share libraries: dl.dll not found
« on: December 12, 2019, 09:48:05 pm »
I test https://www.freepascal.org/docs-html/current/prog/progse56.html where is
Code: Pascal  [Select]
  1. Function dlopen(name: pchar;mode: longint):pointer;cdecl;external ’dl’;
  2. Function dlsym(lib: pointer; name: pchar):pointer;cdecl;external ’dl’;
  3. Function dlclose(lib: pointer):longint;cdecl;external ’dl’;
And I can't find this library in FPC distribution.
I found only c:\svn\fpc\rtl\unix\dl.pp
« Last Edit: December 12, 2019, 09:51:20 pm by Borneq »

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7833
Re: Share libraries: dl.dll not found
« Reply #1 on: December 12, 2019, 09:51:55 pm »
That code and example is for Linux only. A portable substitute is probably using unit dynlibs

Borneq

  • Full Member
  • ***
  • Posts: 213
Re: Share libraries: dl.dll not found
« Reply #2 on: December 12, 2019, 10:09:06 pm »
Thanks, it works (except, it can't change literals in example)
- what do SafeLoadLibrary? I read it save FPU state.
- how share GetMem/FreeMem along dll's/so's ?
- is possible export classes and use it?

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7833
Re: Share libraries: dl.dll not found
« Reply #3 on: December 12, 2019, 10:12:36 pm »
Thanks, it works (except, it can't change literals in example)
- what do SafeLoadLibrary? I read it save FPU state.
- how share GetMem/FreeMem along dll's/so's ?
- is possible export classes and use it?

SafeLoadLibrary, I don't know exactly, for the rest see https://wiki.freepascal.org/packages

PascalDragon

  • Hero Member
  • *****
  • Posts: 890
  • Compiler Developer
Re: Share libraries: dl.dll not found
« Reply #4 on: December 13, 2019, 09:29:43 am »
Thanks, it works (except, it can't change literals in example)
What do you mean?

- what do SafeLoadLibrary? I read it save FPU state.
It stores the FPU and SSE state on x86 processors before loading the library and restores it afterwards.

- how share GetMem/FreeMem along dll's/so's ?
If you simply pass a memory to a library, but the library does not free it (or the other way round) then it will work without problems. However if you have memory that is allocated in e.g. the program, but freed in the library then you need to use a shared memory manager. You can either have both parts use the C memory manager by using the cmem unit or you can pass the program's memory manager to the library (by using GetMemoryManager and SetMemoryManager). A common memory manager is also required if you want to pass managed types like AnsiString or dynamic arrays between the program and the library. Interfaces work without a common memory manager however.

- is possible export classes and use it?
Short answer: no
Long answer: as long as you don't rely on the RTTI (which includes is and as operators as well as exceptions) you can use them. To use them in a safe way requires working dynamic packages support which is still a Work In Progress.