Hello,
I installed Garfield according to Files · 4.0 · garfield / garfieldpp · GitLab (I am using the tag 4.0). Installation worked without issues. I then sourced the setup script source $GARFIELD_INSTALL/share/Garfield/setupGarfield.sh
. The environment variables look fine.
I go to the source code to build an example (Gem
example) which has the following CMakeLists.txt
(Examples/Gem/CMakeLists.txt · 4.0 · garfield / garfieldpp · GitLab)
# ########################################################################################
# Use the code in this section for standalone projects
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(gem)
if(NOT TARGET Garfield::Garfield)
find_package(Garfield REQUIRED)
endif()
# ########################################################################################
# ---Build executable------------------------------------------------------------
add_executable(gem gem.C)
target_link_libraries(gem Garfield::Garfield)
# ---Copy all files locally to the build directory-------------------------------
foreach(_file ELIST.lis MPLIST.lis NLIST.lis PRNSOL.lis)
configure_file(${_file} ${CMAKE_CURRENT_BINARY_DIR}/${_file} COPYONLY)
endforeach()
When doing the cmake
command I get the following error:
lobis@sultan2:~/github/garfieldpp/Examples/Gem/build$ cmake ..
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
CMake Error at CMakeLists.txt:11 (add_executable):
Target "gem" 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?
-- Generating done
-- Build files have been written to: /home/lobis/github/garfieldpp/Examples/Gem/build
lobis@sultan2:~/github/garfieldpp/Examples/Gem/build$
If I change the line target_link_libraries(gem Garfield::Garfield)
to target_link_libraries(gem Garfield)
the example can be built and run correctly.
In order to link to Garfield in my application I follow the instructions, find_package(Garfield REQUIRED)
works OK. However, if I add Garfield::Garfield
to target_link_libraries
I get the following cmake error:
CMake Error at CMakeLists.txt:22 (add_executable):
Target "GarfieldExample" links to target "GSL::gsl" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
I can still compile but it will give errors about missing libraries, using Garfield
or Garfield::Garfield
regardless.
I am using cmake version 3.13.4
Edit: I was building a Docker image to reproduce this problem but the installation / linking works without an issue. I guess there is a problem with my local instalation, any ideas? Thanks!