I am trying to wrap one character with another during a link. As far as I understand, this is easy to do with the ld-wrap option, but on OS X it is not available. There is a βsingle definition: indirect,β here, as I try to trick the main one into typing 42:
a.cpp:
int foo() { return 1; }
b.cpp:
int wrap_foo() { return 42; }
main.cpp:
#include <cstdio> int foo(); int wrap_foo(); int main() { printf("%d\n", foo()); }
How do I create and link them:
$ gcc -c *.o $ gcc -Wl,-i__Z3foov:__Z8wrap_foov *.o duplicate symbol __Z3foov in: ao bo ld: 1 duplicate symbol for architecture x86_64
Is it possible to achieve what I want?
EDIT: In my task, I have no control over a.cpp and main.cpp (there are only objects for them), but I can write any code and do everything I need with objects before the link.
I found the following quistion, which is associated with a similar task (and describes it better) GNU gcc / ld - transferring a call to a character with the caller and the called user defined in the same object file When I read the answers, I see that the case is the same the symbol is already present and I will have a collision.
How to remove foo from ao without touching the source code?
c ++ gcc shared-libraries ld macos
okutane
source share