Segmentation violation when compiling stand alone

I try to compile a standalone with a GUI using gcc in the codeblocks IDE. When running the code with root using root complex_testgui.cpp, everything works without an issue. Also compilation works without any problems. But when I try to run the executable, I get the error:

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007fb8c34a5687 in __GI___waitpid (pid=16257, stat_loc=stat_loc
entry=0x7ffca816c7a8, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:30
#1  0x00007fb8c3410067 in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:149
#2  0x00007fb8c43e7ef3 in TUnixSystem::StackTrace() () from /home/timo/root-6.20.00/mybuild/lib/libCore.so
#3  0x00007fb8c43ea8e4 in TUnixSystem::DispatchSignals(ESignals) () from /home/timo/root-6.20.00/mybuild/lib/libCore.so
#4  <signal handler called>
#5  0x00007fb8bcf84783 in TClingCallFunc::SetArg(long) () from /home/timo/root-6.20.00/mybuild/lib/libCling.so
#6  0x00007fb8c428b60f in TApplication::LoadGraphicsLibs() () from /home/timo/root-6.20.00/mybuild/lib/libCore.so
#7  0x00007fb8c428a9fc in TApplication::InitializeGraphics() () from /home/timo/root-6.20.00/mybuild/lib/libCore.so
#8  0x00007fb8c428fd93 in TApplication::TApplication(char const*, int*, char**, void*, int) () from /home/timo/root-6.20.00/mybuild/lib/libCore.so
#9  0x000055a318a113e8 in main (argc=1, argv=0x7ffca816f5b8) at /home/timo/Schreibtisch/tiffanalysis/Tiff_analysis/complex_testgui.cpp:1022
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x00007fb8bcf84783 in TClingCallFunc::SetArg(long) () from /home/timo/root-6.20.00/mybuild/lib/libCling.so
#6  0x00007fb8c428b60f in TApplication::LoadGraphicsLibs() () from /home/timo/root-6.20.00/mybuild/lib/libCore.so
#7  0x00007fb8c428a9fc in TApplication::InitializeGraphics() () from /home/timo/root-6.20.00/mybuild/lib/libCore.so
#8  0x00007fb8c428fd93 in TApplication::TApplication(char const*, int*, char**, void*, int) () from /home/timo/root-6.20.00/mybuild/lib/libCore.so
#9  0x000055a318a113e8 in main (argc=1, argv=0x7ffca816f5b8) at /home/timo/Schreibtisch/tiffanalysis/Tiff_analysis/complex_testgui.cpp:1022
===========================================================

The line /tiffanalysis/Tiff_analysis/complex_testgui.cpp:1022 is simply

TApplication theApp("App", &argc, argv);

I did build the root version 6.20/00 myself. Probably something went wrong there. When I navigate to the directory /home/timo/root-6.20.00/mybuild/ and type cmake …, I get the following output with a lot of warnings:

-- ROOT default compression algorithm: zlib
-- Found GCC. Major version 7, minor version 5
-- Found a 64bit system
-- Found GNU compiler collection
-- ROOT Platform: linux
-- ROOT Architecture: linuxx8664gcc
-- Build Type: Release (flags = '-O3 -DNDEBUG')
-- Compiler Flags: -O3 -DNDEBUG  -std=c++11 -Wno-implicit-fallthrough -Wno-noexcept-type -pipe  -Wshadow -Wall -W -Woverloaded-virtual -fsigned-char -pthread
-- Looking for ZLib
-- Looking for Freetype
-- Looking for PCRE
-- Building LZMA version 5.2.4 included in ROOT itself
-- Looking for X11
-- Could NOT find GIF (missing: GIF_LIBRARY GIF_INCLUDE_DIR) 
-- Building AfterImage library included in ROOT itself
-- Looking for GSL
-- Downloading and building GSL version 2.5
-- Looking for python
-- Looking for OpenGL
-- Looking for GLEW
-- Looking for LibXml2
-- Looking for MySQL
-- Looking for FFTW3
-- Looking for CFITSIO
-- Looking for TBB
-- Looking for VDT
-- Looking for BLAS for optional parts of TMVA
-- A library with BLAS API not found. Please specify library location.
-- Using GSL CBLAS for optional parts of TMVA
-- Building LLVM in 'Release' mode.
-- Native target architecture is X86
-- Threads disabled.
-- Doxygen disabled.
-- Go bindings disabled.
-- LLVM host triple: x86_64-unknown-linux-gnu
-- LLVM default target triple: x86_64-unknown-linux-gnu
-- Building with -fPIC
-- Constructing LLVMBuild project information
-- Linker detection: GNU ld
-- SysLibs: rt;dl;tinfo;-lpthread;/usr/lib/x86_64-linux-gnu/libz.so
-- Targeting X86
-- Targeting NVPTX
-- Clang version: 5.0.0
-- Cling version (from VERSION file): ROOT_0.7~dev
-- Cling will look for C++ headers in '/usr/include/c++/7:/usr/include/x86_64-linux-gnu/c++/7:/usr/include/c++/7/backward' at runtime.
-- And then fallback to: 'x86_64-linux-gnu-g++-7'
-- Performing Test found_stdstringview
-- Performing Test found_stdstringview - Failed
-- Performing Test found_stdexpstringview
-- Performing Test found_stdexpstringview - Failed
-- Performing Test found_stdapply
-- Performing Test found_stdapply - Failed
-- Performing Test found_stdinvoke
-- Performing Test found_stdinvoke - Failed
-- Performing Test found_stdindexsequence
-- Performing Test found_stdindexsequence - Failed
-- Enabled support for:  asimage builtin_afterimage builtin_clang builtin_gl2ps builtin_gsl builtin_llvm builtin_lz4 builtin_lzma builtin_xxhash builtin_zstd clad dataframe exceptions fftw3 fitsio gdml gsl_shared http imt mathmore mlp minuit2 mysql opengl python roofit runtime_cxxmodules shared ssl tmva tmva-cpu spectrum vdt x11 xml
-- Configuring done
CMake Error in math/vecops/CMakeLists.txt:
  Target "ROOTVecOps" INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "/home/timo/root-6.20.00/mybuild/include"

  which is prefixed in the build directory.


CMake Error in math/vecops/CMakeLists.txt:
  Target "ROOTVecOps" INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "/home/timo/root-6.20.00/mybuild/include"

  which is prefixed in the build directory.Target "ROOTVecOps"
  INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "/home/timo/root-6.20.00/mybuild/include"

  which is prefixed in the source directory.


CMake Error in tmva/tmva/CMakeLists.txt:
  Target "TMVA" INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "/home/timo/root-6.20.00/mybuild/include"

  which is prefixed in the build directory.


CMake Error in tmva/tmva/CMakeLists.txt:
  Target "TMVA" INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "/home/timo/root-6.20.00/mybuild/include"

  which is prefixed in the build directory.Target "TMVA"
  INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "/home/timo/root-6.20.00/mybuild/include"

  which is prefixed in the source directory.


CMake Warning at cmake/modules/RootMacros.cmake:760 (add_library):
  Cannot generate a safe runtime search path for target Genetic because there
  is a cycle in the constraint graph:

    dir 0 is [/home/timo/root-6.20.00/mybuild/lib]
      dir 1 must precede it due to runtime library [libvdt.so]
    dir 1 is [/usr/local/lib]
      dir 0 must precede it due to runtime library [libTMVA.so]

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  cmake/modules/RootMacros.cmake:1145 (ROOT_LINKER_LIBRARY)
  math/genetic/CMakeLists.txt:12 (ROOT_STANDARD_LIBRARY_PACKAGE)


CMake Warning at cmake/modules/RootMacros.cmake:760 (add_library):
  Cannot generate a safe runtime search path for target ROOTVecOps because
  there is a cycle in the constraint graph:

    dir 0 is [/home/timo/root-6.20.00/mybuild/lib]
      dir 1 must precede it due to runtime library [libvdt.so]
    dir 1 is [/usr/local/lib]
      dir 0 must precede it due to runtime library [libCore.so]

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  cmake/modules/RootMacros.cmake:1145 (ROOT_LINKER_LIBRARY)
  math/vecops/CMakeLists.txt:16 (ROOT_STANDARD_LIBRARY_PACKAGE)


CMake Warning at cmake/modules/RootMacros.cmake:760 (add_library):
  Cannot generate a safe runtime search path for target ROOTDataFrame because
  there is a cycle in the constraint graph:

    dir 0 is [/home/timo/root-6.20.00/mybuild/lib]
      dir 1 must precede it due to runtime library [libvdt.so]
    dir 1 is [/usr/local/lib]
      dir 0 must precede it due to runtime library [libTreePlayer.so]

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  cmake/modules/RootMacros.cmake:1145 (ROOT_LINKER_LIBRARY)
  tree/dataframe/CMakeLists.txt:30 (ROOT_STANDARD_LIBRARY_PACKAGE)


CMake Warning at cmake/modules/RootMacros.cmake:760 (add_library):
  Cannot generate a safe runtime search path for target PyROOT because there
  is a cycle in the constraint graph:

    dir 0 is [/home/timo/root-6.20.00/mybuild/lib]
      dir 1 must precede it due to runtime library [libvdt.so]
    dir 1 is [/usr/local/lib]
      dir 0 must precede it due to runtime library [libMathCore.so]

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  cmake/modules/RootMacros.cmake:1145 (ROOT_LINKER_LIBRARY)
  bindings/pyroot/CMakeLists.txt:11 (ROOT_STANDARD_LIBRARY_PACKAGE)


CMake Warning at cmake/modules/RootMacros.cmake:760 (add_library):
  Cannot generate a safe runtime search path for target TMVA because there is
  a cycle in the constraint graph:

    dir 0 is [/home/timo/root-6.20.00/mybuild/lib]
      dir 1 must precede it due to runtime library [libvdt.so]
    dir 1 is [/usr/local/lib]
      dir 0 must precede it due to runtime library [libMinuit.so]

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  cmake/modules/RootMacros.cmake:1145 (ROOT_LINKER_LIBRARY)
  tmva/tmva/CMakeLists.txt:50 (ROOT_STANDARD_LIBRARY_PACKAGE)


CMake Warning at cmake/modules/RootMacros.cmake:760 (add_library):
  Cannot generate a safe runtime search path for target TMVAGui because there
  is a cycle in the constraint graph:

    dir 0 is [/home/timo/root-6.20.00/mybuild/lib]
      dir 1 must precede it due to runtime library [libvdt.so]
    dir 1 is [/usr/local/lib]
      dir 0 must precede it due to runtime library [libTreeViewer.so]

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  cmake/modules/RootMacros.cmake:1145 (ROOT_LINKER_LIBRARY)
  tmva/tmvagui/CMakeLists.txt:12 (ROOT_STANDARD_LIBRARY_PACKAGE)


-- Generating done
-- Build files have been written to: /home/timo/root-6.20.00/mybuild

Any ideas, what the problem is?

_ROOT Version: 6.20/00
_Platform: ubuntu18.04.4
_Compiler:linuxx8664gcc


How did you compile your stand-alone app? Did you use root-config --cflags as compiler flags and root-config --glibs for the libraries? Did you try to run it with gdb?

Thanks a lot bellenot!
I had added all libraries in my root build directory /home/timo/root-6.20.00/mybuild/lib to the list of linked libraries. I now replaced this by the output of root-config --glibs,
and added the compiler options from root-config --cflags . This solved the first problem, thank you very much.
Now, only the problem with the not working buttons remains. I still get the output, that the slots would not exist even though I created the class MyMainFrame in a separate MyMainFrame.h as follows:

#include "Riostream.h"
#include "TH1.h"
#include "TH2.h"
#include "TCanvas.h"
#include <TApplication.h>
#include "TGClient.h"
#include "TGraph.h"
#include "TGraphErrors.h"
#include "TF1.h"
#include "TCollection.h"
#include "TObjArray.h"
class TGTextEntry;
class TGTextButton;
class TGListBox;
class TGNumberEntry;
class TCanvas;
class TH2I;
class TH2D;
class TF1;
class TGraph;
class TGraphErrors;
class TObjArray;

class MyMainFrame : public TGMainFrame {
   RQ_OBJECT("MyMainFrame")
private:
    TGMainFrame *fMainFrame;
//   TGCompositeFrame *fCompositeFrame;
//   TGTextEntry *fTextEntryCalibrationFilm;
    TGTextEntry *fTextEntryCalibrationFilm;
    TGTextButton *fTextButtonQUIT;
    TGTextButton *fTextButtonSelectBackground;
    TGTextButton *fTextButtonSelectRegion;
    TGTextButton *fTextButtonCorrectPixels;
    TGTextButton *fTextButtonSaveCalib;
    TGTextButton *fTextButtonFitHistogram;
    TGTextButton *fTextButtonLoadFilm;
    TGTextButton *fTextButtonFitCalibrationCurveGray;
    TGTextButton *fTextButtonFitCalibrationCurveNetOD;
    TGListBox *fListBoxFluences;
    TGNumberEntry *fTGNumberEntryRebin;
    TGTextButton *fTextButtonRebin;
    TCanvas *coriginal;
    TCanvas *chistogram;
    TCanvas *cCalibGrayvalues;
    TCanvas *cCalibNetOD;
    TH2I *horiginal;
    TH2D *hcorrected;
    TH1I *hhistogram;
    TH1D *hpixelcorrection;
    TH1D *hbackgroundhist;
    Double_t *unidentifiedgrayvalues;
    TGraph *gidentifiedgrayvalues;
    TGraph *gidentifiednetODs;
    TGraphErrors *gCalibrationPointsGray;
    TGraphErrors *gCalibrationPointsNetOD;
    TGraphErrors *gCalibrationUncertainties;
    TF1 *CalibrationCurveNetOD;
    TF1 *CalibrationCurveGray;
    TObjArray *grayvaluecollection = new TObjArray(100);
    TObjArray *netODcollection= new TObjArray(100);
    double gray_empty=58240;
    double gray_empty_error=0;
    int backgroundlines=0;


public:
    MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h);
    //MyMainFrame();
    virtual ~MyMainFrame();
    int LoadFilm();
    int SelectRange();
    int FitHistogram();
    int FitCalibrationCurveNetOD();
    int FitCalibrationCurveGrayValues();
    int SelectBackground();
    int CorrectPixels();
    virtual void CloseWindow();
    int Rebin();

};

Any ideas what the problem is? As I said, it works inside ROOT

You have to generate a dictionary for your MyMainFrame class with rootcling, and add the generated source file to your project
And see also tips for efficient and successful posting

Thanks for your help. This did solve my problem. And sorry for coming up with a second issue, that was not linked to the title problem anymore.

1 Like

You’re welcome. And no problem, don’t worry

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