I had this issue with Code Warrior 10.1 writing software for a HCS08 microcontroller. My solution was to write a small Python script that writes all compiled object files to another file which is then read by the linker.
Note: The following solution works fine for my project. However, some things may need to be changed to work with other projects, targets, compilers etc.
Note: You need to install Python for Windows to make this work. Additionally, you might want to include python into your system's PATH variable.
The Python script
import sys
import os
def main(argv = None):
if (not len(argv) == 3):
myname = os.path.basename(argv[0])
sys.exit("usage: {} <object file name> <linker args file>".format(myname))
obj_arg = "-Add({}) ".format(argv[1])
args_file_name = argv[2]
try:
if os.path.isfile(args_file_name):
with open(args_file_name, 'r') as args_file:
args = args_file.read()
if not obj_arg in args:
with open(args_file_name, 'a') as args_file:
args_file.write(obj_arg)
elif not os.path.exists(args_file_name):
with open(args_file_name, 'w+') as args_file:
args_file.write(obj_arg)
else:
sys.exit("Path '{}' exists but is not a file.".format(args_file_name))
except OSError as err:
sys.exit("Error: " + err.strerror())
if __name__ == "__main__":
main(sys.argv)
Changes to the build system
In the project properties under "C/C++ Build"/"Settings" on the right side I changed the invocation of linker, compiler and assembler as follows:
Under "Linker" --> "Command line pattern" (right side):
python ../scripts/append_object.py """$(MCUToolsBaseDirEnv)\lib\hc08c\lib\ansis.lib""" objlist.args & ${COMMAND} -ArgFile"objlist.args" ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT}
--> Note: I needed to link ansis.lib into the application. So I included it here. For other applications this may be different.
--> The file objlist.args contains all object files as parameters to the linker.
Under "HCS08 Compiler" --> "Command line pattern" (right side):
python ../scripts/append_object.py """${OUTPUT}""" objlist.args & ${COMMAND} ${FLAGS} ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}
--> This writes the name of the object file compiled from a C file to objlist.args.
Under "HCS08 Assembler" --> "Command line pattern" (right side):
python ../scripts/append_object.py """${OUTPUT}""" objlist.args & ${COMMAND} ${FLAGS} -Objn${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}
--> This writes the name of the object file compiled from an assembler file to objlist.args.
Note: The only problem that I encountered was that sometimes old object files are listed if no clean is done but when source files where deleted. in this case, either do a "clean" or delete the build directory to solve this problem.