Archive files (.a suffix) can do this. They contain separate .o files, and
only the ones with symbols that are actually required are linked in. The
rest are not, and that means their global constructors would not appear in
the final output.


On Wed, May 4, 2016 at 8:51 PM, Jian Huang <[email protected]> wrote:

> Let say we have 3 .cpp in our project as below:
>
> //abc.cpp
> #include <iostream>
> class abc
> {
>     public:
>         static int sabc;
> };
>
> int abc::sabc = [](){std::cout << "init abc" << std::endl; return 0;}();
>
> //abcd.cpp
> #include <iostream>
> class abcd
> {
>     public:
>         static int sabcd;
> };
>
> int abcd::sabcd = [](){std::cout << "init abcd" << std::endl; return 0;}();
>
> //test.cpp
> int main()
> {
>     return 0;
> }
>
> Given above .cpp, I build the test executable and run it by following
> typing:
>
> >em++ -std=c++11 abc.cpp abcd.cpp -o abc.bc
> >em++ -std=c++11 abc.bc test.cpp -o test.js
> >node test.js
> init abc
> init abcd
>
> As we see in the output, those static class variables will be initialized
> ahead due to unused abc.obj and abcd.obj will be linked to final
> executable. Is there any way to prevent these unused objs to be linked into
> final executable so that those global variables in them will not be
> initialized?
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to