Results 1 to 4 of 4

Thread: Problems with dynamic linking

  1. #1

    Problems with dynamic linking

    Hello.

    I'm trying to link a DLL dynamicly but I get some errors compiling with FPC, Delphi seems to work right. First I tried this (simplified):[pascal]UNIT example;

    INTERFACE
    the_function: FUNCTION (arg1, arg2: INTEGER): INTEGER; CDECL;

    IMPLEMENTATION

    USES
    UnitBase, { This unit loads the library at INITIALIZATION section. }
    dynlibs;

    INITIALIZATION
    IF the_shared_library <> NilHandler THEN
    the_function := GetProcedureAddress (the_shared_library, 'the_function');

    FINALIZATION

    END.[/pascal] This compiles on Delphi (with some hacks at "UnitBase" to keep compatibility) but on FPC it shows an error message telling that "have POINTER but FUNCTION (blah blah) expected" or similar.

    Then I look at the GL.pas sources and I modified the INITIALIZATION section to[pascal]
    INITIALIZATION
    IF the_shared_library <> NilHandler THEN
    @the_function := GetProcedureAddress (the_shared_library, 'the_function');[/pascal] which also compiles on Delphi but FPC returns "Can't assign a value to an address" but my OpenGL programs compiles and runs right both Linux and Windows. :?

    How do I load a DLL/so/dylib dynamicaly?

    Note that I haven't Internet connection at home so I did wrote all this by memory.
    No signature provided yet.

  2. #2

    Problems with dynamic linking

    i think freepascal requires a "@" before the function name
    From brazil (:

    Pascal pownz!

  3. #3

    Problems with dynamic linking

    FPC's gl.pas probably sets the mode to delphi compatibility. Either ways, to use your method just do:
    pointer(the_function) := GetProcedureAddress (the_shared_library, 'the_function');
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  4. #4

    Problems with dynamic linking

    Quote Originally Posted by JSoftware
    FPC's gl.pas probably sets the mode to delphi compatibility.
    That was the problem. Just added {$MODE DELPHI} and it worked (I want to keep Delphi compatibility too).

    Thanks.
    No signature provided yet.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •