Hi,

        I currently hit an issue that I would like to use a function
statically linked to a shared library but my program use the same
function from another shared library. Here is what I do:

        1. I have toto.cxx that has one function called: toto() {cout <<
"static toto" << endl;}
        2. I create an archive say toto.a has the toto.o
        3. I have toto1.cxx that has one functin called toto() {cout
cout <<"shared toto"<<endl;}
        4. I create a shared libtoto1.so
        5. I have use_toto.cxx that has one function called use_toto() {
toto();}:
        6. I create a shared libuse_toto.so that statically link to
toto.a
        7. My main program test.cxx calling use_toto()

        I would like to always see the output of "static toto" but the
output depends on the order of linking toto1.so and use_toto.so

        I will see "static toto" when I do this
        g++ -o test -L./ -luse_toto -ltoto1.so ./test.o

        But I see "shared toto" if I change the order:
        g++ -o test -L./ -ltoto1.so -luse_toto ./test.o


        My question: do we have any way during the compilation/link to
control the program so that toto() in toto.cxx is always used? Since I
may not have way to control how to build the main program, is there a
way to build libuse_toto.so so that toto() in toto.cxx is always used?

        Thank you very much,

        Hongbo Li  

Reply via email to