Reputation: 126
I am planning to write a library in FPC that can be linked to from other compilers. Dynamic linking (.so, .dll) is no issue, however, the requirement of static linking from (at least) gcc and/or clang has come up.
Somehow, in the end, I need an object archive containing all FPC internal functions, correct? Linking to libc (cmem, cthreads etc.) instead of FPCs implementation appears to be a requirement, but what else would be the most effective and cross-platform way to achieve this?
FPC used is 2.7(trunk).
Thanks in advance.
EDIT: some progress has been made here (german, also see the linked repo in my comment there), but it strikes me as not really elegant nor simple. Also there remains the issue Marco brought up about initialization/finalization...
Upvotes: 1
Views: 1956
Reputation: 398
I had a similar issue and found this tutorial really helpful. It was basically written for iOS development, which would sound much trickier, but worked fairly well for regular C/C++ linkages.
In my case, a legacy Delphi project was used for creating a static library:
fpc -Cn -Mdelphi xxx.dpr
ar -q libxxx.a `grep "\.o$" link.res`
ranlib libxxx.a
Upvotes: 1
Reputation: 26371
Well, in theory you link every .o together with AR, and then call FPC_INITIALIZEUNITS on startup and FPC_FINALIZEUNITS on shutdown.
Maybe however, FPC generates some information (like a table with the addresses of all units ini/fin routines) in the mainmodule. I can't quickly think of a solution for that.
Upvotes: 0