Hi,
I have static TF1 object in my code,
and looks it causes the program to segmentate.
I just wrote simple example demonstrating that problem.
Note that these codes work well in my local computer, but the problem appears
on University computers (gcc version 4.1.2, and root version 5.34/21)
I compile using the following 3 commands:
g++ -c -fPIC test_class.cc -o test_class.o root-config --cflags
root-config --libs
g++ -shared -Wl,-soname,libtest_class.so -o libtest_class.so.1.0.1 test_class.o
g++ test1.cc -o test1.exe root-config --cflags
root-config --libs
-I. -L./ -ltest_class
It compiles without errors.
codes are below
The header file test_class.h
#include <TF1.h>
class test_class
{
public:
test_class();
static TF1 f_lin1;
};
the cc file test_class.cc
#include <TF1.h>
#include "test_class.h"
#include <iostream>
using namespace std;
TF1 test_class::f_lin1 = TF1("f_lin1", "[0] + [1]*x", -45., 45.);
test_class::test_class()
{
cout<<"Kuku"<<endl;
}
The main file test1.cc
#include "test_class.h"
int main()
{
test_class t;
return 0;
}
Rafo
Danilo
January 24, 2015, 3:34pm
2
Hi,
all seems fine also on OSx 10.10, root5 and root6.
There is the possibility that the error is related to a misconfiguration of the system.
Try to modify your “test_class.cc” file:
TF1 test_class::f_lin1(“f_lin1”, “[0] + [1]*x”, -45., 45.);
The commands you show create a “libtest_class.so.1.0.1” file, but the linker needs a “libtest_class.so” file. Can it be that you have some old “libtest_class.so” file around which is not a symbolic link to your “libtest_class.so.1.0.1”?
Thank you for your answers,
I tried TF1 test_class::f_lin1(“f_lin1”, “[0] + [1]*x”, -45., 45.);
it segmentated again.
About the linking of libtest_class.so.1.0.1, yes
I have a link libtest_class.so pointing to libtest_class.so.1.0.1,
so I think this is also ok.
I ran it with valgrind,
and it gives
“Invalid read of size 8”
TFormula::Analyze(char const*, int&, int)
I have no experience with valgrind, I put the output of it, just thought that
it might give you some hint
-bash-3.2$ valgrind ./test1.exe
==12267== Memcheck, a memory error detector
==12267== Copyright (C) 2002-2009, and GNU GPL’d, by Julian Seward et al.
==12267== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
==12267== Command: ./test1.exe
==12267==
==12267== Invalid read of size 8
==12267== at 0x698A659: TFormula::Analyze(char const*, int&, int) (in /net/data/pumpkin1/rafopar/soft/root/root/lib/libHist.so)
==12267== by 0x698C36A: TFormula::Analyze(char const*, int&, int) (in /net/data/pumpkin1/rafopar/soft/root/root/lib/libHist.so)
==12267== by 0x6994F1E: TFormula::Compile(char const*) (in /net/data/pumpkin1/rafopar/soft/root/root/lib/libHist.so)
==12267== by 0x69983B2: TFormula::TFormula(char const*, char const*) (in /net/data/pumpkin1/rafopar/soft/root/root/lib/libHist.so)
==12267== by 0x6976CEE: TF1::TF1(char const*, char const*, double, double) (in /net/data/pumpkin1/rafopar/soft/root/root/lib/libHist.so)
==12267== by 0x9105ADD: __static_initialization_and_destruction_0(int, int) (in /net/data/pumpkin1/rafopar/hps/test/Root/static_obj/libtest_class.so.1.0.1)
==12267== by 0x9105B0A: global constructors keyed to _ZN10test_class6f_lin1E (in /net/data/pumpkin1/rafopar/hps/test/Root/static_obj/libtest_class.so.1.0.1)
==12267== by 0x9105BD5: ??? (in /net/data/pumpkin1/rafopar/hps/test/Root/static_obj/libtest_class.so.1.0.1)
==12267== by 0x910587A: ??? (in /net/data/pumpkin1/rafopar/hps/test/Root/static_obj/libtest_class.so.1.0.1)
==12267== by 0x930798F: ???
==12267== by 0x3AAA00D4AA: call_init (in /lib64/ld-2.5.so)
==12267== by 0x3AAA00D5B4: _dl_init (in /lib64/ld-2.5.so)
==12267== Address 0x1d0 is not stack’d, malloc’d or (recently) free’d
==12267==
==12267==
==12267== Process terminating with default action of signal 11 (SIGSEGV)
==12267== Access not within mapped region at address 0x1D0
==12267== at 0x698A659: TFormula::Analyze(char const*, int&, int) (in /net/data/pumpkin1/rafopar/soft/root/root/lib/libHist.so)
==12267== by 0x698C36A: TFormula::Analyze(char const*, int&, int) (in /net/data/pumpkin1/rafopar/soft/root/root/lib/libHist.so)
==12267== by 0x6994F1E: TFormula::Compile(char const*) (in /net/data/pumpkin1/rafopar/soft/root/root/lib/libHist.so)
==12267== by 0x69983B2: TFormula::TFormula(char const*, char const*) (in /net/data/pumpkin1/rafopar/soft/root/root/lib/libHist.so)
==12267== by 0x6976CEE: TF1::TF1(char const*, char const*, double, double) (in /net/data/pumpkin1/rafopar/soft/root/root/lib/libHist.so)
==12267== by 0x9105ADD: __static_initialization_and_destruction_0(int, int) (in /net/data/pumpkin1/rafopar/hps/test/Root/static_obj/libtest_class.so.1.0.1)
==12267== by 0x9105B0A: global constructors keyed to _ZN10test_class6f_lin1E (in /net/data/pumpkin1/rafopar/hps/test/Root/static_obj/libtest_class.so.1.0.1)
==12267== by 0x9105BD5: ??? (in /net/data/pumpkin1/rafopar/hps/test/Root/static_obj/libtest_class.so.1.0.1)
==12267== by 0x910587A: ??? (in /net/data/pumpkin1/rafopar/hps/test/Root/static_obj/libtest_class.so.1.0.1)
==12267== by 0x930798F: ???
==12267== by 0x3AAA00D4AA: call_init (in /lib64/ld-2.5.so)
==12267== by 0x3AAA00D5B4: _dl_init (in /lib64/ld-2.5.so)
==12267== If you believe this happened as a result of a stack
==12267== overflow in your program’s main thread (unlikely but
==12267== possible), you can try to increase the size of the
==12267== main thread stack using the --main-stacksize= flag.
==12267== The main thread stack size used in this run was 10485760.
==12267==
==12267== HEAP SUMMARY:
==12267== in use at exit: 149,330 bytes in 33 blocks
==12267== total heap usage: 60 allocs, 27 frees, 156,894 bytes allocated
==12267==
==12267== LEAK SUMMARY:
==12267== definitely lost: 0 bytes in 0 blocks
==12267== indirectly lost: 0 bytes in 0 blocks
==12267== possibly lost: 0 bytes in 0 blocks
==12267== still reachable: 149,330 bytes in 33 blocks
==12267== suppressed: 0 bytes in 0 blocks
==12267== Rerun with --leak-check=full to see details of leaked memory
==12267==
==12267== For counts of detected and suppressed errors, rerun with: -v
==12267== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)
Segmentation fault
Well, maybe you could try the newest ROOT v5-34-25 (or the head of v5-34-00-patches branch).
Tried the newst v5-34-25, but again the same thing.
Rafo