Thanks Alon. But due to the linking order of .a is somehow tricky as we 
discussed 
before(https://groups.google.com/forum/#!searchin/emscripten-discuss/jian$20huang/emscripten-discuss/_4qYN_7dvVs/hrf05GesCAAJ),
 
we prefer .bc. Here's the follow-up questions. Why .bc cannot work? Even 
so, should these unnecessary obj can be detected and optimized out in 
linking stage or stage of generating js? 

On Friday, May 6, 2016 at 4:48:58 AM UTC+8, Alon Zakai wrote:
>
> 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] 
> <javascript:>> 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] <javascript:>.
>> 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