An objcopy equivalent for Windows? (Hack for clashing lib symbols)
Asked Answered
P

2

12

I'm looking for a Windows equivalent of the GNU tool objcopy. I'm looking to implement the suggestion posted here to my problem, however I need to do it cross-platform (Windows, Linux and Mac). I couldn't find the answer on my google friend, so perhaps the solution needs to be implemented differently. Thank you!

Proper answered 18/11, 2013 at 16:3 Comment(3)
For use on Visual C++ built files, or on e.g. MinGW/Cygwin built files? In the latte case there should be an objcopy that you can use straight off.Width
Its Visual C++ built files.Proper
I don't know if this is an option for you, but you could just start from ELF linux version, use objcopy and then try the conversion to COFF/PE with the tool released here: agner.org/optimize.Willaims
M
6

Part of the default MSVC tooling: LIB /EXTRACT extracts a copy of an object; LIB /REMOVE then removes it from the library.

I think LIB /DEF /EXPORT:externalName=internalName also would be beneficial to you, when you put the object file back in.

Marven answered 18/11, 2013 at 18:9 Comment(3)
Will that allow me to put a prefix on the symbols?Proper
@Deathicon: Haven't tried it, but I believe that's what EXPORT:prefix_Symbol=Symbol does.Marven
I came across this issue and couldn't get your solution to work with static libraries. Do you have some link that demonstrate this solution?Greening
G
0

If you don't mind a hack, replacing all the instances of the conflicting name by a different name of the same length in one of the library bin file can work. Do this at your own risks.

Example

// a.h
void doSomething();

// b.h
void doSomething();

We can replace doSomething by doSomethink

In python it would be something like:

f = open('b.lib',"rb")
s = f.read()
f.close()
s = s.replace(b'doSomething',b'doSomethink')
f = open('b.lib',"wb")
f.write(s)
f.close()

And modify b header accordingly

// b.h
void doSomethink();

Note that here I used the plain function name as defined in the header to match the symbol in the binary but you might want to use the full mangled name instead to prevent unwanted replacements.

Greening answered 4/1, 2019 at 9:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.