Hi all!
I want to access a global variable in a namespace I put in a shared library. What I observe is that this fails unless I also declare a variable outside any namespace. Consider these files:
test.h
#pragma once
extern double outside;
namespace test {
extern double inside;
}
test.cpp
#include “test.hpp”
double outside;
double test::inside;
test_LinkDef.hpp
#ifdef CINT
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclasses;#pragma link C++ global outside;
#pragma link C++ namespace test;
#pragma link C++ global test::inside;
#endif
build.sh
#!/bin/bash
. /opt/root/6.20.00/bin/thisroot.sh
rootcint -f test_dict.cpp test.hpp test_LinkDef.hppc++ -std=c++17 -fPIC -c test.cpp
c++ -std=c++17 -fPIC -I /opt/root/6.20.00/include -c test_dict.cpp
c++ -std=c++17 -fPIC -shared -o libTest.so test.o test_dict.o -rdynamic
I execute build.sh to compile libTest.so, and all is fine:
root [0] gSystem->Load(“libTest.so”);
root [1] outside
(double) 0.0000000
root [2] test::inside
(double) 0.0000000
Now I remove the
#pragma link C++ global outside;
line in test_LinkDef.hpp and try again:
root [0] gSystem->Load(“libTest.so”);
root [1] test::inside
ROOT_prompt_1:1:1: error: ‘test’ is not a class, namespace, or enumeration
test::inside
^
ROOT_prompt_1:1:1: note: ‘test’ declared here
If this is expected behaviror, it’s at least very strange…
For now, I just have a dummy variable and am fine with it. Still I’d like to know whether I’m doing something wrong, or if I found a bug.
Cheers,
Michael
ROOT Version: 6.20.00
Platform: Linux
Compiler: gcc version 9.2.1 20191008 (Ubuntu 9.2.1-9ubuntu2)