In a nutshell:
{$LinkLib LIBNAME} --> you need the LIBNAME.a file
{$Link LIBNAME} --> you need the LIBNAME.o file
Thanks for that, useful and concise summary.
MarkMLl
Proof of concept:
Lazarus 2.2.2 32-Bit/FPC3.2.2 32-Bit
File: libzvoni.c
#include <stdio.h>
int ZvoniAdd(int a, int b, int* c){
*c=42;
return a+b;
}
I used Geany, and compiled with
gcc -Wall -m32 -c libzvoni.c -o libzvoni.o
(-m32 because i only have Laz/FPC 32-Bit. For 64 leave out the -m32 or specify your own Architecture)
libzvoni.c/libzvoni.o are placed directly besides my lpr/pas files (same folder)
File project1.lpr
program project1;
{$mode objfpc}{$H+}
{$Link libzvoni}
Function ZvoniAdd(Const a:Integer;Const b:Integer;out Surprise:Integer):Integer;cdecl;external;
Var
Check:Integer;
begin
Writeln('Result: ',ZvoniAdd(2,5,Check),'- Surprise: ',Check);
end.
Once your exe is compile, you can remove/rename the o-file for proof, and run it again from console
Note: No Idea about name-mangling.
I did a nm -a on my project1.exe, and found
_ZvoniAdd (Note the underscore)
I admit: definitely not knowledgable about stuff like that