Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get make to figure out the correct dependencies to link in the correct downstream object files?
    primarykey
    data
    text
    <p>I'm going to use a small example for reference. Consider a project with:</p> <pre><code>inner_definitions.o : inner_definitions.cpp inner_definitions.h gcc $^ -o $@ inner_class_1.o : inner_class_1.cpp inner_class_1.h inner_definitions.h gcc $^ -o $@ inner_class_2.o : inner_class_2.cpp inner_class_2.h inner_definitions.h gcc $^ -o $@ outer_class.o : outer_class.cpp outer_class.h inner_class_1.h inner_class_2.h gcc $^ -o $@ executable.o : executable.cpp executable.h outer_class.h gcc $^ -o $@ executable : __?1__ __?2__ </code></pre> <p>But filling in the blanks <code>__?1__</code> for the linker dependencies and <code>__?2__</code> for the linker command isn't easy.</p> <p>In this small example, one could argue that its easy to see that <code>__?1__ = inner_definitions.o inner_class_1.o inner_class_2.o outer_class.o executable.o</code> . However, this is clearly not a scalable solution as it forces each developer to understand all the dependencies of the code they are working with so they can figure out the dependencies <em>by hand</em> rather than by using the <code>make</code> utility.</p> <p>Another solution would be to have a different variable for each object file that listed all its downstream dependencies: i.e <code>__?1__ = executable.o $(executable_dependencies)</code>. This is not a desired solution because it forces the makefile to be compiled in the specific way so the variables are only used when they are fully defined. Also, for really large applications these variables might exceed the maximum variable length.</p> <p>Yet another solution is to use archive .a files for linking. In this case, we could construct an <code>inner_class_1.a</code> that included both <code>inner_defintions.o</code> and <code>inner_class_1.o</code>, so it could be linked with any object file that needed <code>inner_class_1.o</code> without forcing the developer to reconstruct the dependencies. This approach seems promising, but involves having many duplicate files. Also, it doesn't appear that the <code>gcc</code> linker can handle nested archive files.</p> <p>Is there another approach? What is the best approach? Can the <code>gcc</code> linker handle nested archive files?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload