During the preparation of the "controllers" tutorial, I faced a weird linking problem. I wanted to split the huge "controllers.cxx" file so that every controller would be in a sub-file that could be compiled separately and no longer depend on the code from other controllers unless there is a good reason for that. And all of suddens, I had no more factories registered.
Just before that, I had reviewed the factory registering system so that it was enough to just write MomentumFactory mf("momentum");
as a top-level declaration to get everything up and running. But that meant there was no more reference from the main .o files of the game/demo that would require .o files with the factory code (and instance declaration), so they wouldn't be packed in, and certainly wouldn't be initialized either.
So I started thinking about weird mechanisms invoking bool pointers to dummy variables, or no-code functions, and even why not UsingPlatformer
empty class that would extend UsingMomentum
, UsingDpad
and others... Then I realized that all this happened because the .o files (compilation output, that is. Equivalent of your *.OBJ if you're on MS-DOS) are packed into a static library and only pulled to populate the .NDS file on-demand at link-time. If instead I explicitly say "link Demo/*.o Controllers/*.o", they are put into the binary and no trick is needed anymore.
Sunday, April 22, 2018
to $(AR) or not to $(AR)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment