c++ - Why "Multiple definitions linker error" when nm only sees one definition -


when linking object files bunch of errors like:

obj-ia32/shadowroutine.o: in function `initializemap(unsigned int*)': shadowroutine.cpp:(.text+0x0): multiple definition of `initializemap(unsigned int*)' obj-ia32/shadowroutine.o:shadowroutine.cpp:(.text+0x0): first defined here 

with compilation , linking commands of:

g++ -dbigarray_multiplier=1 -wall -wno-unknown-pragmas -fno-stack-protector \     -dtarget_ia32 -dhost_ia32 -dtarget_linux  -i../../../source/include/pin \     -i../../../source/include/pin/gen -i../../../extras/components/include \     -i../../../extras/xed-ia32/include -i../../../source/tools/instlib -o3 \     -fomit-frame-pointer -fno-strict-aliasing -wno-unused-variable \     -wno-unused-function -i. -ishadow-memory -m32 -c \     -o obj-ia32/shadowroutine.o shadowroutine.cpp g++ -dbigarray_multiplier=1 -wall -wno-unknown-pragmas -fno-stack-protector \     -dtarget_ia32 -dhost_ia32 -dtarget_linux  -i../../../source/include/pin \     -i../../../source/include/pin/gen -i../../../extras/components/include \     -i../../../extras/xed-ia32/include -i../../../source/tools/instlib -o3 \     -fomit-frame-pointer -fno-strict-aliasing -wno-unused-variable \     -wno-unused-function -i. -ishadow-memory -m32 -c \     -o obj-ia32/jikes.o jikes.cpp g++ -shared -wl,--hash-style=sysv -wl,-bsymbolic \     -wl,--version-script=../../../source/include/pin/pintool.ver \     -m32 -o obj-ia32/jikes.so obj-ia32/clientreq.o obj-ia32/server.o \     obj-ia32/shadowroutine.o obj-ia32/fncnmap.o obj-ia32/trace.o \     obj-ia32/jikes.o obj-ia32/clientreq.o obj-ia32/server.o \     obj-ia32/shadowroutine.o obj-ia32/fncnmap.o obj-ia32/trace.o \     -l../../../ia32/lib -l../../../ia32/lib-ext -l../../../ia32/runtime/glibc \     -l../../../extras/xed-ia32/lib \     -l/home/karl/r/git/pin/source/tools/jikes/zmq/inst/lib \     -lpin -lxed -lpindwarf -ldl -lzmq 

the 2 object files initializemap jikes.o , shadowroutine.o:

$ nm obj-ia32/jikes.o  | grep initializemap          u _z13initializemappj $ nm obj-ia32/shadowroutine.o | grep initializemap 00000000 t _z13initializemappj $ nm obj-ia32/* | grep initializemap          u _z13initializemappj 00000000 t _z13initializemappj 

so why getting "multiple definitions of initializemap" if it's "defined" in 1 object file , "undefined" in other object file required using extern?

this declarations, definitions, , uses like:

$ grep -r initializemap * jikes.cpp:  if (rtn_name == "sysinitializemap") {       rtn_insert_1(initializemap); binary file obj-ia32/jikes.o matches binary file obj-ia32/shadowroutine.o matches shadowroutine.cpp:void initializemap(addrint *smid) { init_map(*(int*)smid); } shadowroutine.hpp:void initializemap(addrint *smid); 

where both cpp files #include "shadowroutine.hpp".

edit: question why linker command (the third g++ command in second code snippet above) not work though nm says function defined in text of shadowroutine.o , undefined in jikes.o?

you have file obj-ia32/shadowroutine.o listed twice in link command.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -