Yes, this is the standard behavior of .a linking, which emscripten follows.
It links in individual .o files from a .a when they are needed. In scenario
1, a is linked in, after which there are no undefined symbols, so b is not
linked in. But in scenario 2, add2 is still necessary, so b is linked in.
But b contains add, which is a duplicate symbol because of a, and you get
that error.

On Mon, Nov 23, 2015 at 7:09 PM, Jian Huang <[email protected]> wrote:

> Scenario 1:
> //a.cpp
> int add(int a, int b) { return 0; }
> int add2(int a, int b) { return 0; }
> int add3(int a, int b) { return 0; }
>
> b.cpp is identical to a.cpp
>
> //test.cpp
> int add2(int, int);
> int add3(int, int);
> int main(){
> add2(1,1);
> add3(1,1);
> return 0;
> }
>
> Compile and link without error:
> U:\test>emcc -c a.cpp
> U:\test>emcc -c b.cpp
> U:\test>emcc -c test.cpp
> U:\test>emar rc libtest.a a.o b.o
> U:\test>emcc -o test.js test.o libtest.a
>
> Scenario 2:
> //a.cpp
> int add(int a, int b) { return 0; }
> //int add2(int a, int b) { return 0; }
> int add3(int a, int b) { return 0; }
>
> //b.cpp
> int add(int a, int b) { return 0; }
> int add2(int a, int b) { return 0; }
> //int add3(int a, int b) { return 0; }
>
> Compile and link with error:
> U:\test>emcc -c a.cpp
> U:\test>emcc -c b.cpp
> U:\test>emar rc libtest.a a.o b.o
> U:\test>emcc -o test.js test.o libtest.a
> ERROR: Linking globals named '_Z3addii': symbol multiply defined!
>
> My question is why scen2 throw errors but not happen in scen1?  Is this
> the standard behavior of emscripten build-chain?
>
> --
> 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