LCF-AT Posted May 10, 2017 Posted May 10, 2017 Hi guys, so I have a new small problem I need to fix.The problem is that I use two libs in my project and in both are some same function names used and now I get the error message... error LNK2005: _inflateReset2 already defined in 123.lib(123.obj) ...etc ...both libs are from C dlls. So the first question is how I can add both libs (in MASM) who using some same function names?If possible.So I dont wanna change the function names of one dll and create again a lib you know.So what can I do in that case? Thanks
Techlord Posted May 10, 2017 Posted May 10, 2017 (edited) You can do this : Pass -Bsymbolic or -Bsymbolic-functions to the linker. This has a global effect: every reference to a global symbol (of function type for -Bsymbolic-functions) that can be resolved to a symbol in the library is resolved to that symbol. With this you lose the ability to interpose internal library calls to those symbols using LD_PRELOAD. The symbols are still exported, so they can be referenced from outside the library. Use a version script to mark symbols as local to the library, e.g. use something like: {local: bar;}; and pass --version-script=versionfile to the linker. The symbols are not exported. Mark symbols with an approppiate visibility (GCC info page for visibility), which will be either hidden, internal, or protected. protected visibility symbols are exported as .protected, hidden symbols are not exported, and internal symbols are not exported and you compromise not to call them from outside the library, even indirectly through function pointers. You can check which symbols are exported with objdump -T. See here . Another solution : Wrap one or both of these static libraries in a dynamic library (.dll). Then you can change the exported names. See the full solution here . Cheers Edited May 10, 2017 by Techlord Changed formatting 2
LCF-AT Posted May 10, 2017 Author Posted May 10, 2017 Hi, thanks for your answer but it dosent work to add /FORCE:MULTIPLE.So it seems I can only use both if I change these double export names + building again a new lib but this sucks as I told in my first post.Hhmm anyway. greetz 1
Techlord Posted May 10, 2017 Posted May 10, 2017 Hi, thanks for your answer but it dosent work to add /FORCE:MULTIPLE.So it seems I can only use both if I change these double export names + building again a new lib but this sucks as I told in my first post.Hhmm anyway. greetz One way that worked for me in the past would be to simply take a hex-editor and edit out the string references to the offending export name in one of the DLLs, to a new name.. That works for a majority of the DLLs, especially when they do not have decorated names or otehr such complications. That would avoid having to rebuild the libraries all over again. If you do follow this method, do remember to mark your DLL after changing the names of the exports to avoid confusion in the future ! Good luck
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now