Customizing object files

In some cases, it is necessary to re-use object files generated by another task generator to avoid recompilations. This is similar to copy-pasting code, so it is discouraged in general. Another use for this is to enable some compilation flags for specific files. The attribute "add_objects" can be used, like in the following example:

def build(bld):
	some_objects = bld.new_task_gen(
		features       = 'cc', 1
		source         = 'test.c',
		ccflags        = '-O3',
		target         = 'my_objs')

	main = bld.new_task_gen(
		features       = 'cc cprogram',
		source         = 'main.c',
		ccflags        = '-O2', 2
		target         = 'test_c_program',
		add_objects    = 'my_objs') 3
			

1

Files will be compiled in c mode, but no program or library will be produced

1

Different compilation flags may be used

3

The objects will be added automatically in the link stage