First: the compiler itself does not matter but the RTL and FCL and the FPC packages should...be build with -Cg -Xc -XX -CX and maybe -Xs
Second: Why would you need Forms and Interfaces in a shared library? That is bad practice: It will pull in ALL code, since a shared library will never be able to distinguish what you need.
A simple shared library is a few KB on Linux. Add classes for some Pzazz and it is still under 1 MB. (867 KB on ARM-LINUX.Note it still pulls in ALL of classes)
library project1;
{$mode objfpc}{$H+}
uses
Classes{, Forms, Interfaces //are bad design!! for a shared library}
{ you can add units after this };
begin
end.
The template for a shared library looks plainly stupid for Linux, but also in general.
Sensible programmers won't put any GUI code in a shared library. Unless it
IS the shared library, e.g. GTK+ or QT.