# Cmake and make error - garfield

**URL:** <https://root-forum.cern.ch/t/cmake-and-make-error-garfield/49092>\
**Category:** Garfield++\
**Created:** [March 8, 2022, 6:20pm UTC](https://root-forum.cern.ch/t/cmake-and-make-error-garfield/49092 "2022-03-08T18:20:12Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lucas\_Santos\_Sousa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lucas_santos_sousa/32/28320_2.png) [@Lucas\_Santos\_Sousa](https://root-forum.cern.ch/u/Lucas_Santos_Sousa)\
**Post date:** [March 8, 2022, 6:20pm UTC](https://root-forum.cern.ch/t/cmake-and-make-error-garfield/49092/1 "2022-03-08T18:20:13Z")

</div>

CMake error:

```auto
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:

```auto
[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:

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

```

What could it be?

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [March 8, 2022, 7:19pm UTC](https://root-forum.cern.ch/t/cmake-and-make-error-garfield/49092/2 "2022-03-08T19:19:28Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [March 8, 2022, 7:21pm UTC](https://root-forum.cern.ch/t/cmake-and-make-error-garfield/49092/3 "2022-03-08T19:21:19Z")

</div>

See also [Garfield installation issue - #59 by hschindl](https://root-forum.cern.ch/t/garfield-installation-issue/42604/59)

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [March 8, 2022, 7:55pm UTC](https://root-forum.cern.ch/t/cmake-and-make-error-garfield/49092/4 "2022-03-08T19:55:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Lucas\_Santos\_Sousa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lucas_santos_sousa/32/28320_2.png) [@Lucas\_Santos\_Sousa](https://root-forum.cern.ch/u/Lucas_Santos_Sousa)\
**Post date:** [March 8, 2022, 8:12pm UTC](https://root-forum.cern.ch/t/cmake-and-make-error-garfield/49092/5 "2022-03-08T20:12:36Z")

</div>

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:

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

```

The result of `$CMAKE_PREFIX_PATH` gives me:

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

```

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [March 8, 2022, 9:02pm UTC](https://root-forum.cern.ch/t/cmake-and-make-error-garfield/49092/6 "2022-03-08T21:02:33Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Lucas\_Santos\_Sousa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lucas_santos_sousa/32/28320_2.png) [@Lucas\_Santos\_Sousa](https://root-forum.cern.ch/u/Lucas_Santos_Sousa)\
**Post date:** [March 8, 2022, 10:12pm UTC](https://root-forum.cern.ch/t/cmake-and-make-error-garfield/49092/7 "2022-03-08T22:12:47Z")

</div>

> [@hschindl](#):
>
> 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

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

```

results in

```auto
/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

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

```

works well, but the cmake gives an error:

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

```

---

<div class="post-metadata">

**Author:** ![Lucas\_Santos\_Sousa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lucas_santos_sousa/32/28320_2.png) [@Lucas\_Santos\_Sousa](https://root-forum.cern.ch/u/Lucas_Santos_Sousa)\
**Post date:** [March 8, 2022, 11:27pm UTC](https://root-forum.cern.ch/t/cmake-and-make-error-garfield/49092/8 "2022-03-08T23:27:42Z")

</div>

Ok so i have written the make file myself:

```auto
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

```auto
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?

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [March 8, 2022, 11:32pm UTC](https://root-forum.cern.ch/t/cmake-and-make-error-garfield/49092/9 "2022-03-08T23:32:50Z")

</div>

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](https://garfieldpp.web.cern.ch/garfieldpp/getting-started/).

---

<div class="post-metadata">

**Author:** ![Lucas\_Santos\_Sousa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/lucas_santos_sousa/32/28320_2.png) [@Lucas\_Santos\_Sousa](https://root-forum.cern.ch/u/Lucas_Santos_Sousa)\
**Post date:** [March 9, 2022, 12:06am UTC](https://root-forum.cern.ch/t/cmake-and-make-error-garfield/49092/10 "2022-03-09T00:06:35Z")

</div>

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

```auto
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

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [March 23, 2022, 12:07am UTC](https://root-forum.cern.ch/t/cmake-and-make-error-garfield/49092/11 "2022-03-23T00:07:15Z")

</div>

Closed on March 23, 2022, 12:07am UTC

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