Dear all,
I’m trying to build a library with a code composed of several classes, and I encounter a problem. I can reproduce the problem for each class taken individually. The library seems to be built correctly :
[TheVerse:start_test] julien$ make
clang++ -c /Users/julien/Desktop/These/Tools/hap-11-02/start_test/src/Config.C -O2 -pipe -Wall -W -Woverloaded-virtual -pthread -m64 -I/usr/local/root_v5.32.00/include -I/Users/julien/Desktop/These/Tools/hap-11-02/start_test/include -I/opt/local/include -DCONSTRUCT_LIBRARY
/Users/julien/Desktop/These/Tools/hap-11-02/start_test/src/Config.C:155:30: warning: unused parameter 'listname' [-Wunused-parameter]
int Config::ReadList(TString listname)
^
1 warning generated.
/Users/julien/Desktop/These/Tools/hap-11-02/start_test/out/Config.o done!
Generating dictionary /Users/julien/Desktop/These/Tools/hap-11-02/start_test/out/SpectrumDict.C...
rootcint -f /Users/julien/Desktop/These/Tools/hap-11-02/start_test/out/SpectrumDict.C -c -DCONSTRUCT_LIBRARY -O2 -pipe -Wall -W -Woverloaded-virtual -pthread -m64 -I/usr/local/root_v5.32.00/include -I/Users/julien/Desktop/These/Tools/hap-11-02/start_test/include -I/opt/local/include -DCONSTRUCT_LIBRARY -p /Users/julien/Desktop/These/Tools/hap-11-02/start_test/include/Config.hh /Users/julien/Desktop/These/Tools/hap-11-02/start_test/include/LinkDef.hh
/Users/julien/Desktop/These/Tools/hap-11-02/start_test/out/SpectrumDict.C done!
Generating object dictionary /Users/julien/Desktop/These/Tools/hap-11-02/start_test/out/SpectrumDict.o...
clang++ -c /Users/julien/Desktop/These/Tools/hap-11-02/start_test/out/SpectrumDict.C -O2 -pipe -Wall -W -Woverloaded-virtual -pthread -m64 -I/usr/local/root_v5.32.00/include -I/Users/julien/Desktop/These/Tools/hap-11-02/start_test/include -I/opt/local/include -DCONSTRUCT_LIBRARY
/Users/julien/Desktop/These/Tools/hap-11-02/start_test/out/SpectrumDict.o done!
Generating library /Users/julien/Desktop/These/Tools/hap-11-02/start_test/lib/libspectrum.so...
clang++ -dynamiclib -single_module -install_name /Users/julien/Desktop/These/Tools/hap-11-02/start_test/ -O2 -mmacosx-version-min=10.7 -m64 /Users/julien/Desktop/These/Tools/hap-11-02/start_test/out/Config.o /Users/julien/Desktop/These/Tools/hap-11-02/start_test/out/SpectrumDict.o -o /Users/julien/Desktop/These/Tools/hap-11-02/start_test/lib/libspectrum.so -L/usr/local/root_v5.32.00/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lpthread -Wl,-rpath,/usr/local/root_v5.32.00/lib -lm -ldl -L/usr/local/root_v5.32.00/lib -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lpthread -Wl,-rpath,/usr/local/root_v5.32.00/lib -lm -ldl -lMathMore -lMinuit2
/Users/julien/Desktop/These/Tools/hap-11-02/start_test/lib/libspectrum.so done!
clang++ -c /Users/julien/Desktop/These/Tools/hap-11-02/start_test/src/main.C -O2 -pipe -Wall -W -Woverloaded-virtual -pthread -m64 -I/usr/local/root_v5.32.00/include -I/Users/julien/Desktop/These/Tools/hap-11-02/start_test/include -I/opt/local/include -DCONSTRUCT_LIBRARY
/Users/julien/Desktop/These/Tools/hap-11-02/start_test/src/main.C:39:14: warning: unused parameter 'argc' [-Wunused-parameter]
int main(int argc, char **argv) {
^
/Users/julien/Desktop/These/Tools/hap-11-02/start_test/src/main.C:39:27: warning: unused parameter 'argv' [-Wunused-parameter]
int main(int argc, char **argv) {
^
2 warnings generated.
/Users/julien/Desktop/These/Tools/hap-11-02/start_test/out/main.o done!
Generating /Users/julien/Desktop/These/Tools/hap-11-02/start_test/bin/DoFit with library...
clang++ -O2 -mmacosx-version-min=10.7 -m64 /Users/julien/Desktop/These/Tools/hap-11-02/start_test/out/Config.o /Users/julien/Desktop/These/Tools/hap-11-02/start_test/out/SpectrumDict.o /Users/julien/Desktop/These/Tools/hap-11-02/start_test/out/main.o -L/usr/local/root_v5.32.00/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lpthread -Wl,-rpath,/usr/local/root_v5.32.00/lib -lm -ldl -L/opt/local/lib -lgsl -lgslcblas -lMathMore -lMinuit2 -lspectrum -o /Users/julien/Desktop/These/Tools/hap-11-02/start_test/bin/DoFit
/Users/julien/Desktop/These/Tools/hap-11-02/start_test/bin/DoFit done!
But as soon as I tried to load the library in CINT, nothing happened and I can’t instantiate any class :
[TheVerse:start_test] julien$ root -l
root [0] gSystem->Load("lib/libspectrum.so");
root [1] gSystem->ListLibraries()
Loaded shared libraries
=======================
/usr/local/root_v5.32.00/lib/libCint.so
/usr/local/root_v5.32.00/lib/libCore.so
/usr/local/root_v5.32.00/lib/libRint.so
/usr/local/root_v5.32.00/lib/libMathCore.so
/Users/julien/Desktop/These/Tools/hap-11-02/start_test/lib/libspectrum.so
/usr/local/root_v5.32.00/lib/libMatrix.so
/usr/local/root_v5.32.00/lib/libHist.so
/usr/local/root_v5.32.00/lib/libspectrum.so
-----------------------
8 libraries loaded
=======================
root [2] Config *bob;
Error: Symbol Config is not defined in current scope (tmpfile):1:
Error: Symbol bob is not defined in current scope (tmpfile):1:
*** Interpreter error recovered ***
root [3]
You can find attached a Makefile based on the Makefile.arch with one reduce class, a main program and a Linkdef.hh file which produce the same problem :
Here are the Makefile and the Linkdef file :
[ul]
[code]include $(ROOTSYS)/etc/Makefile.arch
Definitions
DOLIBRARY = yes
CURDIR = $(shell pwd)
INCDIR = (shell pwd)/include
SRCDIR = (shell pwd)/src
OUTDIR = (shell pwd)/out
BINDIR = (shell pwd)/bin
LIBDIR = (shell pwd)/lib
DOCDIR = (shell pwd)/doxy
GSLCFLAGS = (shell gsl-config --cflags) GSLLIBS = (shell gsl-config --libs)
CXXFLAGS += -I$(INCDIR) $(GSLCFLAGS)
EXPLLINKLIBS += -lMathMore -lMinuit2
LIBS += $(GSLLIBS) -lMathMore -lMinuit2
EXEC = (BINDIR)/DoFit LIBRARY = (LIBDIR)/libspectrum.so
DIRECTORIES = (LIBDIR) (OUTDIR) (BINDIR) (DOCDIR)
OBJS = $(OUTDIR)/Config.o
INCS = $(INCDIR)/Config.hh
SRCS = $(SRCDIR)/Config.C
ifeq ((DOLIBRARY),yes)
CXXFLAGS += -DCONSTRUCT_LIBRARY
OBJS += (OUTDIR)/SpectrumDict.o
endif
What to do
ifeq ((DOLIBRARY),yes)
all: (DIRECTORIES) (LIBRARY) (EXEC)
else
all: (DIRECTORIES) (EXEC)
endif
directories
(DIRECTORIES) : @mkdir -p @
Library
(LIBRARY) : (OBJS)
@echo "Generating library @..."
(LD) (SOFLAGS) (LDFLAGS) ^ (OutPutOpt) @ (EXPLLINKLIBS)
@echo “$@ done!”
Dictionaries:
(OUTDIR)/SpectrumDict.C : (INCS) (INCDIR)/LinkDef.hh
@echo "Generating dictionary @…"
(ROOTCINT) -f @ -c -DCONSTRUCT_LIBRARY (CXXFLAGS) -p ^
@echo “$@ done!”
executable
(EXEC): (OBJS) (OUTDIR)/main.o
ifeq ((DOLIBRARY),yes)
@echo “Generating @ with library..."
(LD) (LDFLAGS) ^ (LIBS) -lspectrum (OutPutOpt)@
@echo "@ done!”
else
@echo “Generating @ without library..."
(LD) (LDFLAGS) -o (EXEC) (OBJS) (OUTDIR)/main.o (LIBS) (OutPutOpt)@
@echo "@ done!”
endif
sources
(OUTDIR)/main.o: (SRCS) (INCS) (SRCDIR)/main.C
(LD) -c (SRCDIR)/main.C (CXXFLAGS)
@mv *.o (OUTDIR)
@echo “$@ done!”
(OUTDIR)/Config.o: (SRCDIR)/Config.C (INCDIR)/Config.hh
(LD) -c (SRCDIR)/Config.C (CXXFLAGS)
@mv *.o (OUTDIR)
@echo "@ done!"
(OUTDIR)/SpectrumDict.o : (OUTDIR)/SpectrumDict.C
@echo “Generating object dictionary @..."
(CXX) -c < (CXXFLAGS)
@mv *.o (OUTDIR)/
@echo "@ done!”
.PHONY: clean distclean
clean:
rm -rf (OUTDIR)/*.o
rm -rf (OUTDIR)/SpectrumDict.C
rm -rf $(OUTDIR)/SpectrumDict.h
distclean: clean
rm -rf (EXEC)
rm -rf (LIBDIR)/*.so[/code]
[code]#include <Rtypes.h>
#include <Rpair.h>
#include
#include
#include
#ifdef CINT
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclasses;
#pragma link C++ nestedtypedefs;
#pragma link C++ class Config+;
#pragma link C++ class Config::*+;
#endif
[/code]
[/ul]
All my code works fine without generating a library, and you can be sure of that by switching off the library in the Makefile with :
DOLIBRARY = no
I’m using root v5.32.00 with a macbook pro 13’ on mac OS 10.7.3.
Thanks for your help!
Cheers,
Julien
start_test.zip (20.7 KB)