分类: C/C++
2011-05-17 19:07:12
--allow-multiple-definition -z muldefs Normally when a symbol is defined multiple times, the linker will report a fatal error. These options allow multiple definitions and the first definition will be used. |
-Xlinker option Pass option as an option to the linker. You can use this to supply system-specific linker options which GCC does not know how to recognize. If you want to pass an option that takes an argument, you must use -Xlinker twice, once for the option and once for the argument. For example, to pass -assert definitions, you must write -Xlinker -assert -Xlinker definitions. It does not work to write -Xlinker "-assert definitions", because this passes the entire string as a single argument, which is not what the linker expects. -Wl,option Pass option as an option to the linker. If option contains commas, it is split into multiple options at the commas. |
|
|
g++ -o main main.cpp libx.o liby.o |
g++ -o main main.cpp -L./ -lx -ly |
g++ -o main main.cpp -L./ -lx -ly -Wl,--trace-symbol=_Z3foov |
g++ -o main main.cpp -L./ -lx -ly -Wl, --cref |
--redefine-sym old=new Change the name of a symbol old, to new. This can be useful when one is trying link two things together for which you have no source, and there are name collisions. --redefine-syms=filename Apply --redefine-sym to each symbol pair "old new" listed in the file filename. filename is simply a flat file, with one symbol pair per line. Line comments may be introduced by the hash character. This option may be given more than once. |
test: gcc -c test.c gcc -c main.c objcopy --redefine-sym test1=test2 test.o new_test.o objcopy --redefine-sym test1=test2 main.o new_main.o gcc -o $@ new_test.o new_main.o |
debian-wangyao:~/Test/symbol$ ./test in test: test1 debian-wangyao:~/Test/symbol$ nm test.o 0000000d r __func__.1705 U printf 00000000 T test 0000001c T test1 debian-wangyao:~/Test/symbol$ nm new_test.o 0000000d r __func__.1705 U printf 00000000 T test 0000001c T test2 debian-wangyao:~/Test/symbol$ nm main.o 00000000 T main U test1 debian-wangyao:~/Test/symbol$ nm new_main.o 00000000 T main U test2 |
|