Error on shared library in osx 10.9 and c++1 compatibility

Hi,
I’m compiling private classes inheriting from TOBjects and want to create shared libraries on mac osx 10.9.
The same code successfully works on lxplus, with this setup: /afs/cern.ch/sw/lcg/contrib/gcc/4.7.2/x86_64-slc5-gcc47-opt/setup.sh

The code requires c++11 compatibility, so I’m compiling with g++ -std=c++11 -m64 -lstdc++. I’ve new versions of Root (v5-34-21, also recompiled from sources).

My Makefile looks like:

CXX=g++ -std=c++11 -m64 -lstdc++
CXXFLAGS= -DIDSCANDUMP -I${IDSCAN} -I${ROOTSYS}/include -fPIC
LDFLAGS= -lstdc++ -L. -L$(ROOTSYS)/lib -lCore -lHist -lTree

libIDSCAN.so: TrigIDSCANDict.o IDScanEventHeader.o IDScanRoIHeader.o IDScanSpacePoint.o
{CXX} -shared ^ {LDFLAGS} -o @

TrigIDSCANDict.o: TrigIDSCANDict.cxx
{CXX} -g -c {CXXFLAGS} $<

TrigIDSCANDict.cxx: (IDSCAN)/TrigIDSCAN/IDScanEventHeader.h (IDSCAN)/TrigIDSCAN/IDScanRoIHeader.h (IDSCAN)/TrigIDSCAN/IDScanSpacePoint.h (IDSCAN)/TrigIDSCAN/LinkDef.h
rootcint -f @ -c -I{IDSCAN} -p $^
… and then all the classes compiled with CXXFLAGS

Then I have this output:

rootcint -f TrigIDSCANDict.cxx -c -I…/Trigger/TrigAlgorithms/TrigIDSCAN …/Trigger/TrigAlgorithms/TrigIDSCAN/TrigIDSCAN/IDScanEventHeader.h …/Trigger/TrigAlgorithms/TrigIDSCAN/TrigIDSCAN/IDScanRoIHeader.h …/Trigger/TrigAlgorithms/TrigIDSCAN/TrigIDSCAN/IDScanSpacePoint.h …/Trigger/TrigAlgorithms/TrigIDSCAN/TrigIDSCAN/LinkDef.h
g++ -std=c++11 -m64 -lstdc++ -g -c -DIDSCANDUMP -I…/Trigger/TrigAlgorithms/TrigIDSCAN -I/Applications/root/root_v5.34.21.source/include -fPIC TrigIDSCANDict.cxx
g++ -std=c++11 -m64 -lstdc++ -g -c -DIDSCANDUMP -I…/Trigger/TrigAlgorithms/TrigIDSCAN -I/Applications/root/root_v5.34.21.source/include -fPIC …/Trigger/TrigAlgorithms/TrigIDSCAN/src/IDScanEventHeader.cxx
g++ -std=c++11 -m64 -lstdc++ -g -c -DIDSCANDUMP -I…/Trigger/TrigAlgorithms/TrigIDSCAN -I/Applications/root/root_v5.34.21.source/include -fPIC …/Trigger/TrigAlgorithms/TrigIDSCAN/src/IDScanRoIHeader.cxx
g++ -std=c++11 -m64 -lstdc++ -g -c -DIDSCANDUMP -I…/Trigger/TrigAlgorithms/TrigIDSCAN -I/Applications/root/root_v5.34.21.source/include -fPIC …/Trigger/TrigAlgorithms/TrigIDSCAN/src/IDScanSpacePoint.cxx
g++ -std=c++11 -m64 -lstdc++ -shared TrigIDSCANDict.o IDScanEventHeader.o IDScanRoIHeader.o IDScanSpacePoint.o -lstdc++ -L. -L/Applications/root/root_v5.34.21.source/lib -lCore -lHist -lTree -o libIDSCAN.so
Undefined symbols for architecture x86_64:
“_G__add_compiledheader”, referenced from:
_G__set_cpp_environmentTrigIDSCANDict in TrigIDSCANDict.o
“_G__add_setup_func”, referenced from:
G__cpp_setup_initTrigIDSCANDict::G__cpp_setup_initTrigIDSCANDict() in TrigIDSCANDict.o
“_G__call_setup_funcs”, referenced from:
G__cpp_setup_initTrigIDSCANDict::G__cpp_setup_initTrigIDSCANDict() in TrigIDSCANDict.o
“_G__check_setup_version”, referenced from:
_G__cpp_setupTrigIDSCANDict in TrigIDSCANDict.o
“_G__defined_typename”, referenced from:
G__setup_memvarIDScanSpacePoint() in TrigIDSCANDict.o
G__setup_memvarIDScanRoIHeader() in TrigIDSCANDict.o
G__setup_memvarIDScanEventHeader() in TrigIDSCANDict.o
G__setup_memfuncIDScanSpacePoint() in TrigIDSCANDict.o
G__setup_memfuncIDScanRoIHeader() in TrigIDSCANDict.o
G__setup_memfuncIDScanEventHeader() in TrigIDSCANDict.o
“_G__double”, referenced from:


and many others of the same type. So it compiles but the dictionary is not created correctly.
My LinkDef.h file is:

#ifdef CINT

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ nestedclass;
#pragma link C++ nestedtypedefs;

#pragma link C++ class IDScanEventHeader;
#pragma link C++ class IDScanRoIHeader;
#pragma link C++ class IDScanSpacePoint;

#endif

All the classes follow the instructions on how to generate shared libraries (ClassDef(classname,1) in the header, ClassImp(classname) in the cxx). As I said indeed the code works in lxplus.
I think there is a interface problem between my gcc and my root version(s).

I’ve tried these:

  1. gcc version 4.7.4 (MacPorts gcc47 4.7.4_1)

  2. clang/gcc: Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
    Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)

  3. clang++

I also tried root_v6, but had exactly the same error.
I’m adding in the attachments my dictionary as generated during compilation.

I would really thank you if you can help me.
Regards
Francesca
TrigIDSCANDict.cxx (98.1 KB)
TrigIDSCANDict.h (2.93 KB)

Try:
CXXFLAGS= -DIDSCANDUMP -I${IDSCAN} -fPIC root-config --cflags
LDFLAGS= -lstdc++ -L. root-config --ldflags --libs
Also, try to modify the rootcint rule (somehow the “-p” flag is missing in the output):
rootcint -f $@ -c -p -I${IDSCAN} $^

Works! sorry, I inherited the flags and didn’t realize they where wrong/obsolete.
Thanks a lot,
francesca

Hi,
I have still problems since the code I need to compile need g++11 features that clang++ (the default compiler on macosx) does not support (for reference, the VLA of structures). So I need to recompile root with gcc48, instead of the default clang. When configuring root I see only few options for macosx, mainly:
macosx64 for MacOS X >= 10.5 with gcc 4.0 64 bit mode

which sets

Checking for C++ compiler … clang++

How can i change the compiler?

Regards,
francesca

Hi, I changed the strategy. I separated the code in two parts: one using and compiling Root classes with old compiler, one linking the Root classes already created and compiling the rest with a new gcc48 compiler. So problem is solved.
Thanks

francesca