Compilation of a macro with -std=c++11 flag

Hello,

I am trying to run a macro which compiles some other macros in ROOT (Version 5.34), and some of the header files need C++ 11. I run a script which looks like this:

#!/bin/bash

COMPILE_LOGON=“~/analysis_master/customize_root/compile_logon.C”

root.exe -n $COMPILE_LOGON <<EOF
.L detector.hh++
.q
EOF

Where compile_logon.C is a ROOT macro which looks like this:

{
#include “string”
string ANAHOME=“~/”;
string tmp;

tmp = ANAHOME; tmp += “analysis_master/lib/lib64/root”;
char* inc = gSystem->ExpandPathName(tmp.c_str());
gInterpreter->AddIncludePath(inc);
delete inc;

gSystem->SetMakeSharedLib("g++ -std=c++11 -c $Opt -I. -I/user/sweeper/develop/unpacker/library/inc -fPIC $IncludePath $SourceFiles ; g++ $ObjectFiles -shared -L/user/sweeper/develop/unpacker/library/src -lSweeperUnpacker -Wl,-rpath=/user/sweeper/develop/unpacker/library/src -Wl,-soname,$LibName.so -m64 -O2 $LinkedLibs -o $SharedLib");

tmp = ANAHOME; tmp += “analysis_master/include”;
char* inc = gSystem->ExpandPathName(tmp.c_str());
gInterpreter->AddIncludePath(inc);
delete inc;
tmp = ANAHOME; tmp += “analysis_master/customize_root”;
char* inc = gSystem->ExpandPathName(tmp.c_str());
char* inc = gSystem->ExpandPathName(“~/analysis_master/customize_root”);
gInterpreter->AddIncludePath(inc);
gInterpreter->AddIncludePath(“/user/sweeper/develop/unpacker/library/inc”);
gSystem->SetFlagsDebug(“-std=c++11”);
gSystem->AddLinkedLibs(“-std=c++11”);
gSystem->SetFlagsOpt(“-std=c++11”);
delete inc;
}

As you can see, we have tried various ways to get the compiler to recognize the “-std=c++11” flag. But when I run it, I get an error which looks like this:

/usr/include/c++/4.9/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support for the
^
Error: external preprocessing failed. :0:
!!!Removing /user/e15091/analysis_master/src/sweeper_cc_ACLiC_dict.cxx /user/e15091/analysis_master/src/sweeper_cc_ACLiC_dict.h !!!
Error: /mnt/misc/sw/x86_64/Debian/8/root/gnu/5.34.32/bin/rootcint: error loading headers…
Error in : Dictionary generation failed!
Info in : Invoking compiler to check macro’s validity
Info in : The compiler has not found any problem with your macro.
Probably your macro uses something rootcint can’t parse.
Check http://root.cern.ch/viewvc/branches/v5-34-00-patches/cint/doc/limitati.txt for Cint’s limitations.

So despite all of our attempts, it seems like the compiler still doesn’t recognize the C++ 11 flag, and the compilation is failing.

Is there something I can do to get rid of this error?

Thank you.

You will probably have to move to ROOT 6 if you need C++11. The old CINT interpreter lacks support for a variety of C++ features and that was the main reason it was replaced with cling in ROOT 6.

Hello,

I was able to get it to compile properly on ROOT 6.06/02, but now when I run my compiled code I am getting this error:

cling::DynamicLibraryManager::loadLibrary(): libCint.so.5: cannot open shared object file: No such file or directory

I don’t know why it would be looking for a CINT shared object file, shouldn’t it be CLING? Any idea what could be causing this?

Thank you.

Did you pass -lCint during compilation? How did you compile your program?

I don’t pass -lCint anywhere that I am aware of. To compile I just ran the script above, except now in ROOT 6 instead of ROOT 5.

Doesn’t this line:

gSystem->SetMakeSharedLib("g++ -std=c++11-c $Opt -I. -I/user/sweeper/develop/unpacker/library/inc -fPIC $IncludePath $SourceFiles ; g++ $ObjectFiles -shared -L/user/sweeper/develop/unpacker/library/src -lSweeperUnpacker -Wl,-rpath=/user/sweeper/develop/unpacker/library/src -Wl,-soname,$LibName.so -m64 -O2 $LinkedLibs -o $SharedLib");

contain all the flags that I am passing to the compiler?

I also commented out these:

//gSystem->SetFlagsDebug("-std=c++11");
//gSystem->AddLinkedLibs("-std=c++11");
//gSystem->SetFlagsOpt("-std=c++11");

because they didn’t seem to be necessary.

Do you have the same problem if you compile from the command line? Something needs to be pointing to ROOT5 still for you to end up with a binary that requires libCint rather than libCling.

I realized now that the error

cling::DynamicLibraryManager::loadLibrary(): libCint.so.5: cannot open shared object file: No such file or directory

comes up whenever I open ROOT. So it’s not caused by me compiling/running my program. I think there is a path somewhere which is still pointing to something related to ROOT 5 instead of ROOT 6 for some reason.

Thanks for the help.

Hi,

as Guilherme says, you need to use ROOT6 to take advantage of new C++ stadards.
The error here points indeed to a faulty installation of ROOT. I would remove entirely ROOT5 from the system and start from scratch with ROOT6.

Cheers,
D

I found a path which was accidentally left pointing to a ROOT logon macro pointing to the ROOT 5 installation. Once I fixed that, the problems went away. My original code compiles and runs properly in ROOT 6.

Thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.