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!
Asked
Active
Viewed 7,253 times
11
-
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. – Some programmer dude Nov 18 '13 at 16:06
-
Its Visual C++ built files. – Erunehtar Nov 18 '13 at 16:22
-
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. – Jekyll Nov 18 '13 at 17:39
2 Answers
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.

MSalters
- 173,980
- 10
- 155
- 350
-
-
@Deathicon: Haven't tried it, but I believe that's what `EXPORT:prefix_Symbol=Symbol` does. – MSalters Nov 19 '13 at 14:01
-
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? – Guillaume Gris Jan 04 '19 at 08:31
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.

Guillaume Gris
- 2,135
- 17
- 34