07-22-2024, 10:19 AM
Usually the linker is smart enough to only link those object files, which contain used references. In C/C++ you would just create one translation unit per function, hence getting a single .o file for every function. You may also collect those single object in a .a file, but even therein it remains a collection of single objects, they will not be concatenated on a binary level, but just saved in one file. However, ALL user code in a .bas program, i.e. all your main code and all SUBs/FUNCs go into one translation unit (doesn't matter if it's in the main file or $INCLUDE'd). The linker is not able to tear that unit to avoid unused code. If just one of the funtions in the unit is referenced, then the unit is linked in whole, and as your main code IS usually referenced it WILL be linked.
Saying that, the only way to achive what you want, is to split your libraries into one SUB/FUNC per include file (or maybe small collections of SUBs/FUNCs which are definitly used together) and $INCLUDE only those which you need in your program. That way you only have the really needed code in the big user code unit. Placing an $INCLUDEONCE in each include file will help to avoid double definition errors, if you nest $INCLUDEs to pull in other required SUBs/FUNCs.
Saying that, the only way to achive what you want, is to split your libraries into one SUB/FUNC per include file (or maybe small collections of SUBs/FUNCs which are definitly used together) and $INCLUDE only those which you need in your program. That way you only have the really needed code in the big user code unit. Placing an $INCLUDEONCE in each include file will help to avoid double definition errors, if you nest $INCLUDEs to pull in other required SUBs/FUNCs.
GuiTools, Blankers & other Projects:
https://qb64phoenix.com/forum/forumdisplay.php?fid=32
Libraries & useful Functions:
https://qb64phoenix.com/forum/forumdisplay.php?fid=23
https://qb64phoenix.com/forum/forumdisplay.php?fid=32
Libraries & useful Functions:
https://qb64phoenix.com/forum/forumdisplay.php?fid=23