Run twice a macro with vectors of defined size

Hello,
I have a problem executing the macro attached, using vectors of defined size:

#include <vector>

int test(){
  vector <int> myvec(70);
  cout <<"test" <<endl;
  return 0;
}

It runs ones correctly with .x test.C, but re-running it without exiting ROOT, it gives the following message:

IncrementalExecutor::executeFunction: symbol '_ZSt27__uninitialized_default_n_aIPimiET_S1_T0_RSaIT1_E' unresolved while linking [cling interface function]!
You are probably missing the definition of int* std::__uninitialized_default_n_a<int*, unsigned long, int>(int*, unsigned long, std::allocator<int>&)
Maybe you need to load the corresponding shared library?

How could I solve the problem? Thanks for any input.

Hi,
please see the discussion at

Macro reloading’s support is flaky (but better in 6.22 than previous versions).
The problem stems from the fact that C++ is not okay with duplicated symbols.

Cheers,
Enrico

Thanks Enrico, I thought the problem was related to the vectors of defined size, because declaring vectors without size and filling them, the macro was simply working.

I think it’s just that using a different constructor makes the ROOT interpreter generate different code, and some code is ok with reloading, some code is not. In general, reloading macros is not well-supported.

Common workarounds are loading the macro once with .L and executing the function test() multiple times, or running the macro from the terminal with root -l -b -q test.C, which starts a new interpreter every time.

Cheers,
Enrico

OK, thanks for the suggestion.

Cheers,
Francesca

1 Like