Ich bin eine Schritt weiter gekommen, es hat mit der Ausrichtung zu tun.
Wen ich folgendes ins Hauptprogramm schreibe, dann geht es:
Das kommt daher, weil cglm AVX-Register verwendet.
https://www.freepascal.org/daily/doc/prog/progsu9.html
Also folgender Testcode funktioniert.
Code: Alles auswählen
program project1;
const
{$IFDEF Linux}
libcglm = 'cglm';
{$ENDIF}
{$IFDEF Windows}
libcglm = 'libcglm-0.dll';
{$ENDIF}
{$CODEALIGN LOCALMIN=16}
type
Tvec4 = array[0..3] of single;
Tmat4 = array[0..3] of Tvec4;
procedure glmc_mat4_identity(mat: Tmat4); cdecl; external libcglm;
procedure printMatrix(const m: Tmat4);
var
y, x: integer;
begin
for y := 0 to 3 do begin
for x := 0 to 3 do begin
Write(m[y, x]: 4: 2, ' ');
end;
WriteLn();
end;
WriteLn();
end;
procedure main;
var
mat_ID: integer;
m: Tmat4;
begin
glmc_mat4_identity(m);
printMatrix(m);
end;
begin
main;
end.
Aber ein Schönheitsfehler hat es doch noch, will ich es in der Unit mit der Bindung habe, dann knallt es trotzdem, das "{$CODEALIGN LOCALMIN=16}" muss zwingen ins Hauptprogramm.
Unit:
Code: Alles auswählen
unit Unit1;
interface
const
{$IFDEF Linux}
libcglm = 'cglm';
{$ENDIF}
{$IFDEF Windows}
libcglm = 'libcglm-0.dll';
{$ENDIF}
{$CODEALIGN LOCALMIN=16}
type
Tvec4 = array[0..3] of single;
Tmat4 = array[0..3] of Tvec4;
procedure glmc_mat4_identity(mat: Tmat4); cdecl; external libcglm;
implementation
end.
Hauptprogramm:
Code: Alles auswählen
program project1;
uses Unit1;
procedure printMatrix(const m: Tmat4);
var
y, x: integer;
begin
for y := 0 to 3 do begin
for x := 0 to 3 do begin
Write(m[y, x]: 4: 2, ' ');
end;
WriteLn();
end;
WriteLn();
end;
procedure main;
var
mat_ID: integer;
m: Tmat4;
begin
glmc_mat4_identity(m); // Bum !
printMatrix(m);
end;
begin
main;
end.
Darum die nächste Frage, kann man das "{$CODEALIGN LOCALMIN=16}" irgendwie in die Unit auslagern ?
Und wieso wird das "var mat_ID: integer;" nicht weg optimiert, ich dachte immer FPC entfernt unbenutztes ?