NOSQLITE3STATIC
NOLIBDEFLATESTATIC
You can do this on command line or if IDE , for example lazarus ide :
Project Options -> Compiler Options -> Custom Options
I've done this for a different reason then you and I don't recommend it unless you are a seasoned veteran of writing external libraries. Things like shared memory will be prohibited because the framework wasn't designed with relocatable code in mind. mORMot has a lot of initialization hooks that hook into exceptions, rtti and system units and while there are (some) compile time flags that control this behavior it really goes against the "grain" of the project and may result in unwanted behavior.
That much said, if you don't care about shared memory, mORMot will work just fine in a library after all, without shared memory there's little difference between a program and a library.
For your use case I fail to see why you would want to use a library instead of a normal program, everything you mentioned can be achieved with writing a normal program and in your case there's only disadvantages to using a library instead.
Why use a library?
Just run an executable, not a library, from your main service.
My idea is to compile the mormot2 server with everything it needs to a library:
1. A .dll for windows that can be loaded/unloaded by a simple windows service that checks if a updated version of the dll exists and does the dirty job: download it, verify integrity, stops the mormot2 server, unloads the dll, updates the dll, reload itself the dll, start again the mormot2 server
2. A .so library for linux that it is loaded by a linux executable that runs as a service with the excellent TSynDaemon and does the same thing as the windows service.
As I am not so experienced as you, what do you think of this idea? What are the possible problems that I could arrive to? Does it needs something special? Do you propose something else?
I already managed to compile a small mormot2 server as windows DLL with both Delphi and Lazarus/fpc, and it works from a windows service.
I have not managed to do the same thing in linux with Lazarus/fpc as I am receiving the following linker error when compiling the same library:
Verbose: Linking C:\pchr\projects\pchr\servers\fpc\libserverlib.so
Debug: C:\fpcupdeluxe\fpcupdeluxe\cross\bin\x86_64-linux\x86_64-linux-ld.exe: C:\DG\mORMot2\src\db\..\..\static\x86_64-linux\sqlite3.o: relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
Debug: C:\fpcupdeluxe\fpcupdeluxe\cross\bin\x86_64-linux\x86_64-linux-ld.exe: C:\DG\mORMot2\src\core\..\..\static\x86_64-linux\libdeflatepas.a(adler32.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
Debug: C:\fpcupdeluxe\fpcupdeluxe\cross\bin\x86_64-linux\x86_64-linux-ld.exe: C:\DG\mORMot2\src\core\..\..\static\x86_64-linux\libdeflatepas.a(crc32.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
Debug: C:\fpcupdeluxe\fpcupdeluxe\cross\bin\x86_64-linux\x86_64-linux-ld.exe: C:\DG\mORMot2\src\core\..\..\static\x86_64-linux\libdeflatepas.a(deflate_compress.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
Debug: C:\fpcupdeluxe\fpcupdeluxe\cross\bin\x86_64-linux\x86_64-linux-ld.exe: C:\DG\mORMot2\src\core\..\..\static\x86_64-linux\libdeflatepas.a(deflate_decompress.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
C:\fpcupdeluxe\fpcupdeluxe\cross\bin\x86_64-linux\x86_64-linux-ld.exe: final link failed: Nonrepresentable section on output
I am beginner with fpc and I have not managed to find anything about that. I have put the -fPIC in custom options and I have tried to use the options in "Compilation and Linking" without success
An probably this has to do with the compiled units from static.
Can you help me?