CMake unable to check existing PkgConfig modules

I tried to add dpdk libraries to my test application, and, almost everything related PkgConfig went wrong.

At moment i have:

  • Arch
  • Clion IDE
  • CMake 3.24
  • dpdk 22.0

CMakeLists.txt is very simple helloworld-like application

cmake_minimum_required(VERSION 3.24)

project(test-dpdk)

find_package(PkgConfig)
pkg_check_modules(DPDK REQUIRED libdpdk)

add_executable(server main.cpp)
target_link_libraries(server PRIVATE PkgConfig::DPDK)

Which gives me following output:

-- The C compiler identification is GNU 12.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "1.8.0") 
-- Checking for module 'libdpdk'
--   Package 'libdpdk', required by 'virtual:world', not found
CMake Error at /app/extra/clion/bin/cmake/linux/share/cmake-3.24/Modules/FindPkgConfig.cmake:607 (message):
  A required package was not found
Call Stack (most recent call first):
  /app/extra/clion/bin/cmake/linux/share/cmake-3.24/Modules/FindPkgConfig.cmake:829 (_pkg_check_modules_internal)
  CMakeLists.txt:10 (pkg_check_modules)

I checked that pkg-config itself knows where are libraries located:

> pkg-config --libs libdpdk
-Wl,--as-needed -lrte_node -lrte_graph -lrte_flow_classify -lrte_pipeline -lrte_table -lrte_pdump -lrte_port -lrte_fib -lrte_ipsec -lrte_vhost -lrte_stack -lrte_security -lrte_sched -lrte_reorder -lrte_rib -lrte_dmadev -lrte_regexdev -lrte_rawdev -lrte_power -lrte_pcapng -lrte_member -lrte_lpm -lrte_latencystats -lrte_kni -lrte_jobstats -lrte_ip_frag -lrte_gso -lrte_gro -lrte_gpudev -lrte_eventdev -lrte_efd -lrte_distributor -lrte_cryptodev -lrte_compressdev -lrte_cfgfile -lrte_bpf -lrte_bitratestats -lrte_bbdev -lrte_acl -lrte_timer -lrte_hash -lrte_metrics -lrte_cmdline -lrte_pci -lrte_ethdev -lrte_meter -lrte_net -lrte_mbuf -lrte_mempool -lrte_rcu -lrte_ring -lrte_eal -lrte_telemetry -lrte_kvargs -lbsd 
> pkg-config --modversion libdpdk
22.07.0
> pkg-config --path libdpdk      
/usr/lib/pkgconfig/libdpdk.pc

Contents of a libdpdk.pc are fine and correct.

After a while i realized that setting up PKG_CONFIG_PATH ENV variable may help, but, unfortunately it had no effect.

CLion CMake debugger led to FindPkgConfig.cmake:588 execute_process (with a pkg-config --print-errors --short-errors --exists libdpdk query) which resulted an error, but, if manually executed via terminal it returns success.

So, the questions is how to force PkgConfig to pick libraries (installed system-wide) from CMakeLists? Are there any obvious things i forgot? Is it a bug?

Thanks in advance.

UPD
Calling CMake directly resolves issue, so, it may be caused by IDE and ENV collisions, not a CMake. Thanks for an attention :sweat_smile:

1 Like

I tried to add dpdk libraries to my test application, and, almost everything
related PkgConfig went wrong.

At moment i have:

  • Arch
  • Clion IDE
  • CMake 3.24
  • dpdk 22.0

CMakeLists.txt is very simple helloworld-like application

cmake_minimum_required(VERSION 3.24)

project(test-dpdk)

find_package(PkgConfig)
pkg_check_modules(DPDK REQUIRED libdpdk)

This is missing IMPORTED_TARGET if you want to use the target below, but that
is unrelated to the problems you are seeing.

add_executable(server main.cpp)
target_link_libraries(server PRIVATE PkgConfig::DPDK)

Which gives me following output:

– Checking for module ‘libdpdk’
– Package ‘libdpdk’, required by ‘virtual:world’, not found
CMake Error at
/app/extra/clion/bin/cmake/linux/share/cmake-3.24/Modules/FindPkgConfig.cma
ke:607 (message): A required package was not found
Call Stack (most recent call first):
/app/extra/clion/bin/cmake/linux/share/cmake-3.24/Modules/FindPkgConfig.cma
ke:829 (_pkg_check_modules_internal) CMakeLists.txt:10 (pkg_check_modules)

I checked that pkg-config itself knows where are libraries located:

CLion CMake debugger led to FindPkgConfig.cmake:588 execute_process (with a
pkg-config --print-errors --short-errors --exists libdpdk query) which
resulted an error, but, if manually executed via terminal it returns
success.

So, the questions is how to force PkgConfig to pick libraries (installed
system-wide) from CMakeLists? Are there any obvious things i forgot? Is it
a bug?

It looks like it should work. Some things that may be part of the problem:

  • there are multiple pkg-config executables, and CMake picks up another one
  • some environment variables, likely some PKG_* ones, are influencing what you
    see and are missing for the CMake run. You could try running the calls with an
    empty environment via “env”.

Eike