Partially compile C ++ source code

purpose

I want to be able to extract some information from a collection of C ++ source files, partially compiling them. I say that we are partially compiling, because I do not have access to all the shared libraries with which it should link. The exact situation will be explained below.

In pseudo code, I have (roughly) the following structure:

class AParent : public AClassFromSharedLib {
    ...
    void setup(void);
    void otherThings(void);
    ...
}

class AChild : public AParent {
    ...
    void setup(void);
    void moreStuff(void);
    ...
}
...
AParent::setup(void)
{
    interestingFunction("foo");
    interestingFunction("bar");
    interestingFunction("baz");
    somethingElse("cafe");
}
...
AChild::setup(void)
{
    super::setup();
    interestingFunction("dead");
    interestingFunction("beef");
    somethingElse("babe");
}
...
REGISTER_CLASS("SomeName", AChild);

All I want to do is print the arguments interestingFunctionfrom the method invocation path setup()for AChild(and other objects registered through REGISTER_CLASS).

SomeName:
    "foo"
    "bar"
    "baz"
    "dead"
    "beef"

I do not care. Just a hierarchy of objects and a method setupis all I really need to accomplish what I want.

: " , setup, ". ? RedHat 5 g++ 4.4.x.

.so , , , .so. , . , . , , .

, , , .so, , , . , , .

, , , , . , , , .., . - .

, gcc . , , , . , -Os -fdata-sections -ffunction-sections -Wl,--gc-sections - . -flto, , .

-Wl,--unresolved-symbols=ignore-in-object-files, segfault , undefined main().

, . - grep ( , ..), . , .

+4

Source: https://habr.com/ru/post/1610679/


All Articles