Hello,
I’m trying to implement a class (which inherits from TNamed) which has a member function that calls qsort to sort an array of type double. I need to implement a comparator function for this to work; however, when I try to make the comparator a member function of my class I get the compiler error:
g++ -g -Wno-conversion -fPIC -D_REENTRANT -I/Users/mschmid7/root/include -I. -c -o TNMLHisto.o TNMLHisto.cc
TNMLHisto.cc: In member function ‘bool TNMLHisto::optimize(const double*, int, int, double, double, double*, int&)’:
TNMLHisto.cc:398: error: argument of type ‘int (TNMLHisto::)(const void*, const void*)’ does not match ‘int ()(const void, const void*)’
which makes sense, since qsort needs a pointer to a function of type int. So, I move the function definition outside of my class, and I find that I now have a rootcint-related error:
g++ -g -Wno-conversion -fPIC -D_REENTRANT -I/Users/mschmid7/root/include -I. -c -o TNMLHisto.o TNMLHisto.cc
Generating dictionary …
rootcint -f TNMLHistoDict.C -c TNMLHisto.hh LinkDef.hh
g++ -g -Wno-conversion -fPIC -D_REENTRANT -I/Users/mschmid7/root/include -I. -c -o TNMLHistoDict.o TNMLHistoDict.C
Linking …
g++ -dynamiclib -o libTNMLHisto.so TNMLHisto.o TNMLHistoDict.o -L/Users/mschmid7/root/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lfreetype -lpthread -lm -ldl -lMinuit -lRooFitCore -lRooFit
ld: multiple definitions of symbol _Z13double_comparPKvS0
TNMLHisto.o definition of _Z13double_comparPKvS0 in section (__TEXT,__text)
TNMLHistoDict.o definition of _Z13double_comparPKvS0 in section (__TEXT,__text)
ld: multiple definitions of symbol _Z13double_comparPKvS0.eh
TNMLHisto.o definition of absolute _Z13double_comparPKvS0.eh (value 0x0)
TNMLHistoDict.o definition of absolute _Z13double_comparPKvS0.eh (value 0x0)
/usr/bin/libtool: internal link edit command failed
make: *** [libTNMLHisto.so] Error 1
I’m guessing this has to do with my LinkDef file. I’ve tried linking the function: double_compar using the statement:
#pragma link C++ function double_compar;
but this doesn’t have any effect. Any suggestions? This seems like it would be a common problem to anyone trying to use qsort.
Thanks,
Michael