# CMake unable to check existing PkgConfig modules

**URL:** https://discourse.cmake.org/t/cmake-unable-to-check-existing-pkgconfig-modules/7121
**Category:** Usage
**Created:** [December 23, 2022, 5:00am UTC](https://discourse.cmake.org/t/cmake-unable-to-check-existing-pkgconfig-modules/7121 "2022-12-23T05:00:00Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![michael.k](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@michael.k](https://discourse.cmake.org/u/michael.k)
#### Post date: [December 23, 2022, 5:00am UTC](https://discourse.cmake.org/t/cmake-unable-to-check-existing-pkgconfig-modules/7121/1 "2022-12-23T05:00:00Z")

</div>

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

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

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

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

---

<div class="post-metadata">

### Author: ![Dakon](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dakon/32/854_2.png) [@Dakon](https://discourse.cmake.org/u/Dakon)
#### Post date: [December 30, 2022, 4:53am UTC](https://discourse.cmake.org/t/cmake-unable-to-check-existing-pkgconfig-modules/7121/2 "2022-12-30T04:53:48Z")

</div>

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