Hello
Can somebody tell me how to build a shared library containing classes which derive from classes in another shared library with cygwin ?
To put it simply, I have a library libKVMultiDet.dll containing classes derived from ROOT classes. Another library libKVIndra.dll should contain classes derived from the ROOT classes and from those in libKVMultiDet.dll. With linux this is simply achieved by adding libKVMultiDet.so to the list of libraries to link with when building libKVIndra.so.
If I try to do the same thing with cygwin I end up with lots of ‘multiply defined symbol’ errors because all the ROOT classes are defined twice. If I don’t link with libKVMultiDet.dll then obviously all the classes in it are undefined, and it doesn’t work either.
My Makefiles are all based on test/Makefile and test/Makefile.arch; however I have also tried the suggestions in include/compiledata.h (variable MAKESHAREDLIB etc.) - by the way, why do the compile/linker options in this file differ significantly from the win32gcc target in test/Makefile.arch ?
In this case, the build of the 1st library looks like this:
g++ KVBase.o KVDetectorEvent.o KVDetector.o KVEvent.o KVList.o KVRList.o KVMaterial.o KVModule.o KVMult
iDetArray.o KVNucleus.o KVParticle.o KVPosition.o KVRing.o KVTelescope.o KVTestEvent.o KVLayer.o KVGrou
p.o KVCalibrator.o KVReconstructedNucleus.o KVBrowser.o KVDetectorBrowser.o KVWidget.o KVWidgetList.o K
VMultiDetBrowser.o KVLayerBrowser.o KVRingBrowser.o KVBrowserWidget.o KVACQParam.o KVBrowserNameDialog.
o KVTarget.o KVDataBase.o KVDBKey.o KVDBRecord.o KVDBTable.o KVRegister.o KVIDTelescope.o KV2Body.o KVD
ataBaseBrowser.o KVIDLine.o KVIDZLine.o KVIDZALine.o KVIDGrid.o KVIDZGrid.o KVIDZAGrid.o KVRegBinary.o
KVIDGridManager.o KVMultiDetDict.o -shared -Wl,-soname,libKVMultiDet.dll -Wl,–enable-auto-image-base -
Wl,–export-all-symbols -L/usr/X11R6/lib -L/cygdrive/c/root/lib -lCore -lCint -lHist -lGraf -lGraf3d -l
Gpad -lTree -lMatrix -lRint -lPhysics -lGui -o libKVMultiDet.dll
Info: resolving _gRandom by linking to __imp__gRandom (auto-import)
Info: resolving vtable for TNamedby linking to __imp___ZTV6TNamed (auto-import)
Info: resolving vtable for TIterby linking to __imp___ZTV5TIter (auto-import)
Info: resolving _gROOT by linking to __imp__gROOT (auto-import)
Info: resolving _gClient by linking to __imp__gClient (auto-import)
Info: resolving vtable for TCollectionby linking to __imp___ZTV11TCollection (auto-import)
Info: resolving vtable for TSeqCollectionby linking to __imp___ZTV14TSeqCollection (auto-import)
Info: resolving vtable for TListby linking to __imp___ZTV5TList (auto-import)
Info: resolving vtable for TRefby linking to __imp___ZTV4TRef (auto-import)
Info: resolving vtable for TGLayoutHintsby linking to __imp___ZTV13TGLayoutHints (auto-import)
Info: resolving vtable for TGHorizontalFrameby linking to __imp___ZTV17TGHorizontalFrame (auto-import)
Info: resolving vtable for TGTransientFrameby linking to __imp___ZTV16TGTransientFrame (auto-import)
Info: resolving vtable for TStringby linking to __imp___ZTV7TString (auto-import)
Info: resolving vtable for TQClassby linking to __imp___ZTV7TQClass (auto-import)
Info: resolving vtable for TGObjectby linking to __imp___ZTV8TGObject (auto-import)
Info: resolving vtable for TGWindowby linking to __imp___ZTV8TGWindow (auto-import)
Info: resolving vtable for TGFrameby linking to __imp___ZTV7TGFrame (auto-import)
Info: resolving vtable for TGCompositeFrameby linking to __imp___ZTV16TGCompositeFrame (auto-import)
Info: resolving vtable for TGTabby linking to __imp___ZTV5TGTab (auto-import)
Info: resolving vtable for TGMainFrameby linking to __imp___ZTV11TGMainFrame (auto-import)
libKVMultiDet.dll done
This library works fine on its own - I can load it in an interactive session and play with the classes no problem.
Then I try to build the 2nd library and get :
g++ KVINDRA.o KVSilicon.o KVChIo.o KVCsI.o KVPhoswich.o KVINDRAReconNuc.o KVINDRAReconEvent.o KVChannelVolt.o KVVoltEnergyAlpha.o KVChannelEnergyAlpha.o KVDBParameterSet.o KVDBRun.o KVDBSystem.o KVDBTape.o KVINDRACodes.o KVDBAlphaPeak.o KVINDRADB.o KVLineCSV.o KVINDRACodeMask.o KVChannelEnergyBrho.o KVIDSiCsI.o KVIDChIoSi.o KVIDCsI.o KVLineDST.o KVINDRADB1.o KVUpDater.o KVUpDater1.o KVINDRADB2.o KVUpDater2.o KVINDRA2.o KVINDRADB4.o KVUpDater4.o KVINDRA4.o KVIDPhoswich.o KVIDChIoCsI.o KVIDChIoSi75.o KVIDSi75SiLi.o KVIDSiLiCsI.o KVDBElasticPeak.o KVDBPeak.o KVChannelEnergyChIo.o KVLightEnergyCsI.o KVIDCsIRLLine.o KVIDGCsI.o KVIDGChIoSi.o KVIndraDict.o -shared -Wl,-soname,libKVIndra.dll -Wl,–enable-auto-image-base -Wl,–export-all-symbols -L/home/frankland/lib -lKVMultiDet -L/usr/X11R6/lib -L/cygdrive/c/root/lib -lCore -lCint -lHist -lGraf -lGraf3d -lGpad -lTree -lMatrix -lRint -lPhysics -o libKVIndra.dll
and the results are (I only include a few lines, there are far too many):
/home/frankland/lib/libKVMultiDet.dll(.text+0x0):streambuf-inst.cc: multiple definition of ___do_sjlj_init' /usr/lib/gcc-lib/i686-pc-cygwin/3.3.3/crtbegin.o(.text+0x0):crtstuff.c: first defined here /home/frankland/lib/libKVMultiDet.dll(.text+0xd92c0):streambuf-inst.cc: multiple definition of
KVBase::List()'
KVINDRA.o(.text$_ZN6KVBase4ListEv[KVBase::List()]+0x0):KVINDRA.cpp: first defined here
/home/frankland/lib/libKVMultiDet.dll(.text+0xdb6c0):streambuf-inst.cc: multiple definition of TNamed::IsSortable() const' KVINDRA.o(.text$_ZNK6TNamed10IsSortableEv[TNamed::IsSortable() const]+0x0):KVINDRA.cpp: first defined here /home/frankland/lib/libKVMultiDet.dll(.text+0xdb6d0):streambuf-inst.cc: multiple definition of
TNamed::Hash() const’
KVINDRA.o(.text$_ZNK6TNamed4HashEv[TNamed::Hash() const]+0x0):KVINDRA.cpp: first defined here
/home/frankland/lib/libKVMultiDet.dll(.text+0xdb6f0):streambuf-inst.cc: multiple definition of `TNamed::GetName() const’
KVINDRA.o(.text$_ZNK6TNamed7GetNameEv[TNamed::GetName() const]+0x0):KVINDRA.cpp: first defined here
etc. etc. etc.
Apologies if this is a trivial problem, but I haven’t found the answer anywhere on the web site, in the user’s guide, in the forum, or root-talk digest.
Thanks for any help
John.