<div dir="ltr">Hi all,<div><br></div><div>I'm dealing with an annoying problem with the linker, that I realize is non-standard usage but I'm hoping CMake can help.</div><div><br></div><div>The main question is, is there any way in CMake to use OBJECT libraries but still represent dependency graph information?</div>
<div><br></div><div>I have a bunch of global variables with constructors that have important side-effects (I know...), and for build graph sanity, these get linked into static libraries which depend on each other. When we link executables, some object files get excluded because they only have global variables that aren't referenced anywhere else (because their constructors are supposed to "register" them), and then of course that code just doesn't make it in to the executable.</div>
<div><br></div><div>It looks like I have three options:</div><div><br></div><div>1. Manually insert a reference to each object file in the compilation unit containing main(). This means manually maintaining this list and possibly forgetting to add things in the future.</div>
<div><br></div><div>2. Use -Wl,-whole-archive. This approach is at odds with CMake's helpful static library dependency (and mutual dependency) tracking and resolution, and can result in multiple definition errors as often as it results in forgetting to include object files.</div>
<div><br></div><div>2.5. It's possible to use -Wl,-whole-archive just on some libraries, not the depended-on ones, but this has a similar problem to options 1 and 3, in that we need to manually maintain a list of "important" libraries.</div>
<div><br></div><div>3. Make every library an OBJECT library. AFAICT this requires listing every library in the dependency graph in the add_executable() directive, and not having dependency information tracked locally to the library that has the dependency. There also may be ordering issues I haven't discovered yet.</div>
<div><br></div><div>What would be wonderful is if CMake could track dependencies for OBJECT libraries the same way it tracks them for STATIC libraries. Is this planned somewhere? Does it already exist in a property I haven't seen yet?<br clear="all">
<div><br></div>-- <br>Cheers,<br>Leif
</div></div>