I have a problem. I can't get to work correctly my application with gcc-compiled library.
Here the code of library:
#include <stdio.h>
typedef struct
{
double x;
double y;
} Vect;
void test( Vect a, Vect b, double r )
{
printf( "% .2f, % .2f\n", a.x, a.y );
printf( "% .2f, % .2f\n", b.x, b.y );
printf( "% .2f\n", r );
}
void test2( double ax, double ay, double bx, double by, double r )
{
printf( "% .2f, % .2f\n", ax, ay );
printf( "% .2f, % .2f\n", bx, by );
printf( "% .2f\n", r );
}
Here the code of application:
program demo;
type
Vect = record
x : Double;
y : Double;
end;
function dlopen ( Name : PChar; Flags : longint) : Pointer; cdecl; external 'dl';
function dlclose( Lib : Pointer) : Longint; cdecl; external 'dl';
function dlsym ( Lib : Pointer; Name : Pchar) : Pointer; cdecl; external 'dl';
var
a, b : Vect;
r : Double;
test : procedure( a : Vect; b : Vect; r : Double ); cdecl;
test2 : procedure( ax : Double; ay : Double; bx : Double; by : Double; r : Double ); cdecl;
libtest : Pointer;
begin
libtest := dlopen( './a.out', $001 );
test := dlsym( libtest, 'test' );
test2 := dlsym( libtest, 'test2' );
a.x := 10;
a.y := 10;
b.x := 100;
b.y := 100;
r := 1000;
test( a, b, r );
writeln( '==========' );
test2( a.x, a.y, b.x, b.y, r );
end.
Commands for compilation are:
gcc -shared lib.c -O3 -s -fPIC
fpc demo.pas -O3 -Xs -Sd
Result:
1000.00, 0.00
0.00, 0.00
0.00
==========
10.00, 10.00
100.00, 100.00
1000.00
FreePascal version: 2.4.2
GCC version: 4.5.1 and 4.4.4
What have I missed? Some options for compilers? Or this is a bug of FreePascal? The same code compiled in 32-bit mode works fine.