That only works because you linked it into a FPC program which has all the symbols that might be needed anyway. If you'd link the library into a C program you'd get errors about missing symbols - in your specific case related to the Writeln.
Yes, thats the issue now
Facts
1. libnothing.a has nothing.o inside
2. nothing.o uses SysUtils
3. nothing.o has 1 procedure (named "ints") using IntToStr
{$linklib libnothing.a} + "ints" works if full RTL is provided with -Fu <-- this is because of what you saidNow, assume I have only ppc386.exe, or its not even FPC but a different language, how do I link in full RTL from a single .a file?
I did:
- go to units\i386-win32\rtl
- unpack all .a (libimp*.a) to get .o files
- AR all .o to single .a
I have ~9 MB .a file with full RTL
If I
{$linklib librtl.a}
and {$linklib libnothing.a}
and call "ints"
and dont provide a path to the RTL with -Fu
= I get an error there is no RTL, "cannot find system"
So I created minimal RTL - system.pas, sysinitpas.pas, objpas.pas and fpintres.pas
This minimal RTL alone works fine, I can import some functions from WinAPI and use them. Binary output is exactly 3.5 kB (header + 6 sections, 512 bytes align), thats nice.
Back to librtl.a, if I include this file with minimal RTL I get these errors: (and more)
Error: Multiple defined symbol "fpc_pchar_to_shortstr"
Error: Multiple defined symbol "FPC_PCHAR_TO_SHORTSTR"
Error: Multiple defined symbol "fpc_ansistr_decr_ref"
Error: Multiple defined symbol "FPC_ANSISTR_DECR_REF"
Error: Multiple defined symbol "fpc_ansistr_assign"
Error: Multiple defined symbol "FPC_ANSISTR_ASSIGN"
I assume thats not because there are 2 versions (lower and upper case), but there are multiple .o's with these functions
So I looked in what files "fpc_pchar_to_shortstr" exists
grep -Ril "fpc_pchar_to_shortstr" .
./dos.o
./exeinfo.o
./heaptrc.o
./strings.o
./strings.ppu
./system.o
./system.ppu
./sysutils.o
So these functions exists in multple files, so If I create all-in-one RTL there will be duplicates.
Im stuck here.
Can RTL be shipped in one .a file?
Or FPC is just a bad choice to build static libraries and I should give up?