By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,897 Members | 1,955 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,897 IT Pros & Developers. It's quick & easy.

how to control to use the function static linked to a shared library

P: 1

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
5. I have use_toto.cxx that has one function called use_toto() { toto();}:
6. I create a shared 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 and

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

But I see "shared toto" if I change the order:
g++ -o test -L./ -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 so that toto() in toto.cxx is always used?

Thank you very much,

Hongbo Li
Jun 28 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.