Recent

Author Topic: Are Libraries possible? (DLL/DSO's)  (Read 24559 times)

tlacuache

  • New Member
  • *
  • Posts: 14
    • http://grovers.us/seth
RE: Re: RE: Re: RE: changes...
« Reply #30 on: December 12, 2006, 03:56:54 pm »
So, if we can compile dll's/so's with FPC, somebody please explain this to me (this is from http://freepascal.org/faq.var):
Quote

3.  Dynamic libraries

These operating systems do support shared libraries (also called dynamic link libraries), Free Pascal currently does not emit position independant code (PIC), as required for the creation of shared libraries.

Therefore, even though the linux compiler target permits creating shared libraries, the usage of that shared library may result in undefined behavior, especially if accessing global variables in the library. Creation of shared libraries is not recommended with the current version of the compiler.

Importing code from shared libraries does work as expected though, since it does not require usage of position independant code.


How does that apply to what we've been talking about?

tlacuache

  • New Member
  • *
  • Posts: 14
    • http://grovers.us/seth
RE: Re: RE: Re: RE: changes...
« Reply #31 on: December 12, 2006, 05:46:36 pm »
Actually, I guess I wasn't reading in context. I think the answer to my own question is that "it depends on the OS", because the above quote was referring to UNIX'es. Windows seems to be fully supported, UNIX and it variants are "not recommended", and some of the other ones aren't even possible. Has anyone noticed the problems mentioned in association with UNIX as discussed in 6.3 of that faq?

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: RE: Re: RE: Re: RE: changes...
« Reply #32 on: December 12, 2006, 06:12:13 pm »
I think the FAQ is wrong (maybe it´s very old, and wasn´t updated). Apache modules require exporting global variables, and they work perfectly on Linux.

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: RE: Re: RE: changes...
« Reply #33 on: December 12, 2006, 06:16:28 pm »
Quote from: "krisleech"

The call:
Code: [Select]

apr_table_vdo(@ProcessHeader,PChar(''),r^.headers_in,PChar(''));



^ Is that enough?


Actually I also need to know where you are calling apr_table_vdo.

A simplified compilable example would be great.

krisleech

  • New Member
  • *
  • Posts: 43
Are Libraries possible? (DLL/DSO's)
« Reply #34 on: December 14, 2006, 12:29:40 pm »
Hi Sekel, I'm calling apr_table_vdo from a TObject decended class constructor. And am populating a TStringList (for now) with the key and value. At the moment I am using a a global TStringList instead of passing it to ProcessHeader using the rec pointer.

The strange thing is this, I now have key and value aligning correctly... To do this I have the callback procedure type defined with stdcall but ProcessHeaders defined with cdecl!!

Code: [Select]

type
  apr_table_do_callback_fn_t = function (rec: Pointer;
   const key, value: PChar): Integer; stdcall;


Code: [Select]

function ProcessHeader(rec: Pointer; const key, value: PChar): Integer; cdecl;
begin
  TmpHeaders.add(PChar(key),PChar(value));
  result := 1;
end;


Out of intrest the above does not work in objfpc mode, you get as would be expected the following compiler error:

Code: [Select]
Error: Incompatible type for arg no. 1: Got "<address of function(Pointer,const PChar,const PChar):LongInt;CDecl>", expected "<procedure variable type of function(Pointer,const PChar,const PChar):LongInt;StdCall>"


However we are working in Delphi mode, and so provided this is acurate Delphi behaviour it is not a problem for me.

I'll try and put together a simplyified unit later today...

 

TinyPortal © 2005-2018