Cmake and make error - garfield

CMake error:

CMake Error at CMakeLists.txt:16 (add_executable):
  Target "build" links to target "Garfield::Garfield" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?


Even with this cmake error, the make is available to be run, so running it.

Make error:

[100%] Linking CXX executable build
/cvmfs/sft.cern.ch/lcg/releases/binutils/2.34-990b2/x86_64-centos7/bin/ld: cannot find -lGarfield::Garfield

Maybe the make error has something to do with the cmake error, even so, i don’t know how to fix any of them.

The error on cmake the terminal is talking about is refering to this part of CMakeLists.txt:

cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(SGpp)
if(NOT TARGET Garfield::Garfield)
  find_package(Garfield REQUIRED)
endif()

What could it be?

@hschindl can help more, but you could already try to add the location of where Garfield is installed in the CMAKE_PREFIX_PATH environment variable

See also Garfield installation issue - #59 by hschindl

Hi,
indeed, can you check if you sourced the script setupGarfield.sh before running CMake?

Yes, before i run the cmake i have typed this on terminal:
source /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/setup.sh
To make sure everything went right, i always type echo $GARFIELD_HOME, and i get that:

-bash: /cvmfs/sft.cern.ch/lcg/releases/LCG_97/./Garfield++/HEAD/x86_64-centos7-gcc9-opt

The result of $CMAKE_PREFIX_PATH gives me:

-bash: /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt

Hi,
the version of Garfield++ that was included in LCG97 is quite old by now. I would really recommend cloning the master branch and building it yourself…

Hello. Thank you. Could you elaborate a little more with what you mean to cloning the master branch and build it myself? I think i didn’t got it.

There is also another two versions more recent than the LCG97:

LCG98

source /cvmfs/sft.cern.ch/lcg/views/LCG_98/x86_64-ubuntu1804-gcc8-opt/setup.sh

results in

/cvmfs/sft.cern.ch/lcg/releases/R/3.6.3-96764/x86_64-ubuntu1804-gcc8-opt/lib/R/bin/exec/R: error while loading shared libraries: libreadline.so.7: cannot open shared object file: No such file or directory
/cvmfs/sft.cern.ch/lcg/releases/R/3.6.3-96764/x86_64-ubuntu1804-gcc8-opt/lib/R/bin/exec/R: error while loading shared libraries: libreadline.so.7: cannot open shared object file: No such file or directory
/cvmfs/sft.cern.ch/lcg/releases/R/3.6.3-96764/x86_64-ubuntu1804-gcc8-opt/lib/R/bin/exec/R: error while loading shared libraries: libreadline.so.7: cannot open shared object file: No such file or directory
/cvmfs/sft.cern.ch/lcg/releases/R/3.6.3-96764/x86_64-ubuntu1804-gcc8-opt/lib/R/bin/exec/R: error while loading shared libraries: libreadline.so.7: cannot open shared object file: No such file or directory
/cvmfs/sft.cern.ch/lcg/releases/R/3.6.3-96764/x86_64-ubuntu1804-gcc8-opt/lib/R/bin/exec/R: error while loading shared libraries: libreadline.so.7: cannot open shared object file: No such file or directory

and
LCG_99

source /cvmfs/sft.cern.ch/lcg/views/LCG_99/x86_64-ubuntu2004-gcc9-opt/setup.sh

works well, but the cmake gives an error:

cmake: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

Ok so i have written the make file myself:

PROJ_NAME=build


OBJDIR = $(GARFIELD_HOME)/Object
SRCDIR = $(GARFIELD_HOME)/Source
INCDIR = $(GARFIELD_HOME)/Include
HEEDDIR = $(GARFIELD_HOME)/Heed
LIBDIR = $(GARFIELD_HOME)/Library
C_SOURCE=/sampa/lucas19/garfield/GarfieldDetector.cc
H_SOURCE=/sampa/lucas19/garfield/*.hh

OBJ=$(C_SOURCE:.cc=.o)

CC=gcc

CXX = `root-config --cxx`

CC_FLAGS=-c	\
-W	\
`root-config --cflags` \
-03 -fno-common \
-I$(INCDIR) -I$(HEEDDIR) \
-Wall	\
-ansi	\
-pedantic	\
-std=c++17	\

LDFLAGS = -L$(LIBDIR) -lGarfield
LDFLAGS += `root-config --glibs --cflags --libs` -lGeom -lgfortran -lm

all: $(PROJ_NAME)

$(PROJ_NAME): $(OBJ)
	$(CC) -o $@ $^

%.o: %.cc %.hh
	$(CC) -o $@ $< $(CC_FLAGS)
 
main.o: main.cc $(H_SOURCE)
	$(CC) -o $@ $< $(CC_FLAGS)
 
clean:
	rm -rf *.o $(PROJ_NAME) *~

The problem now is

n file included from /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TString.h:28,
                 from /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TNamed.h:26,
                 from /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TVirtualX.h:30,
                 from /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TVirtualPad.h:27,
                 from /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TPad.h:16,
                 from /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TCanvas.h:17,
                 from /sampa/lucas19/garfield/GarfieldDetector.cc:11:
/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/ROOT/RStringView.hxx:84:17: error: expected type-specifier
   84 |        operator std::string_view() const { return std::string_view(fData,fLength); }
      |                 ^~~
In file included from /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TNamed.h:26,
                 from /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TVirtualX.h:30,
                 from /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TVirtualPad.h:27,
                 from /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TPad.h:16,
                 from /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TCanvas.h:17,
                 from /sampa/lucas19/garfield/GarfieldDetector.cc:11:
/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TString.h:110:13: error: expected type-specifier
  110 |    operator std::string_view() const { return std::string_view(Data(),fExtent); }
      |             ^~~
/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TString.h:275:32: error: ‘string_view’ in namespace ‘std’ does not name a type
  275 |    explicit TString(const std::string_view &sub);
      |                                ^~~~~~~~~~~
/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TString.h:275:27: note: ‘std::string_view’ is only available from C++17 onwards
  275 |    explicit TString(const std::string_view &sub);
      |                           ^~~
/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TString.h:312:37: error: ‘string_view’ in namespace ‘std’ does not name a type
  312 |    TString    &operator=(const std::string_view &s);
      |                                     ^~~~~~~~~~~
/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TString.h:312:32: note: ‘std::string_view’ is only available from C++17 onwards
  312 |    TString    &operator=(const std::string_view &s);
      |                                ^~~
/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TString.h:439:9: error: ‘string_view’ in namespace ‘std’ does not name a type
  439 |    std::string_view View() const { return std::string_view(GetPointer(),Length()); }
      |         ^~~~~~~~~~~
/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TString.h:439:4: note: ‘std::string_view’ is only available from C++17 onwards
  439 |    std::string_view View() const { return std::string_view(GetPointer(),Length()); }
      |    ^~~
In file included from /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TNamed.h:26,
                 from /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TVirtualX.h:30,
                 from /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TVirtualPad.h:27,
                 from /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TPad.h:16,
                 from /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TCanvas.h:17,
                 from /sampa/lucas19/garfield/GarfieldDetector.cc:11:
/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TString.h:834:53: error: ‘string_view’ in namespace ‘std’ does not name a type
  834 | inline Bool_t operator==(const char *s1, const std::string_view &s2)
      |                                                     ^~~~~~~~~~~
/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TString.h:834:48: note: ‘std::string_view’ is only available from C++17 onwards
  834 | inline Bool_t operator==(const char *s1, const std::string_view &s2)
      |                                                ^~~
/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TString.h:834:15: error: ‘Bool_t operator==(const char*, const int&)’ must have an argument of class or enumerated type
  834 | inline Bool_t operator==(const char *s1, const std::string_view &s2)
      |               ^~~~~~~~
/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TString.h:839:37: error: ‘string_view’ in namespace ‘std’ does not name a type
  839 | inline Bool_t operator==(const std::string_view &s1, const char *s2)
      |                                     ^~~~~~~~~~~
/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TString.h:839:32: note: ‘std::string_view’ is only available from C++17 onwards
  839 | inline Bool_t operator==(const std::string_view &s1, const char *s2)
      |                                ^~~
/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TString.h:839:15: error: ‘Bool_t operator==(const int&, const char*)’ must have an argument of class or enumerated type
  839 | inline Bool_t operator==(const std::string_view &s1, const char *s2)
      |               ^~~~~~~~
/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TString.h:852:37: error: ‘string_view’ in namespace ‘std’ does not name a type
  852 |   std::string printValue(const std::string_view* val);
      |                                     ^~~~~~~~~~~
/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-centos7-gcc9-opt/include/TString.h:852:32: note: ‘std::string_view’ is only available from C++17 onwards
  852 |   std::string printValue(const std::string_view* val);
      |                                ^~~
make: ** [] Erro 1

Do you know what could it be?

Hi,
sorry, what I meant is: set up the environment using one of the LCG views like you did; then git clone the Garfield++ source and build the project following the instructions on the website.

1 Like

Oh :o It was not necessary to do that. In fact, the link you have posted has the answer to my problem XD

source /cvmfs/sft.cern.ch/lcg/views/LCG_101/x86_64-centos7-gcc11-opt/setup.sh

is what i should use, not the ones i was using before.

Thank you

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