# .cmake fail to find libbfd header file bfd.h

**URL:** https://discourse.cmake.org/t/cmake-fail-to-find-libbfd-header-file-bfd-h/8470
**Category:** Usage
**Tags:** os:linux
**Created:** [July 6, 2023, 9:09am UTC](https://discourse.cmake.org/t/cmake-fail-to-find-libbfd-header-file-bfd-h/8470 "2023-07-06T09:09:13Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![koteswararao18](https://discourse.cmake.org/user_avatar/discourse.cmake.org/koteswararao18/32/3587_2.png) [@koteswararao18](https://discourse.cmake.org/u/koteswararao18)
#### Post date: [July 6, 2023, 9:09am UTC](https://discourse.cmake.org/t/cmake-fail-to-find-libbfd-header-file-bfd-h/8470/1 "2023-07-06T09:09:13Z")

</div>

Hi,  
Configuring bpftrace-0.17.1 ([GitHub - iovisor/bpftrace: High-level tracing language for Linux eBPF](https://github.com/iovisor/bpftrace)) during build phase failing in finding libbfd header file (bfd.h). bpftrace cmake structure is given below.

```auto
bpftrace-0.17.1
		├── build
		├── CMakeLists.txt
		├── cmake
				├── FindLibBfd.cmake
				          └── CHECK_CXX_SOURCE_COMPILES("
#include <string.h>
// See comment in bfd-disasm.cpp for why this needs to exist
#define PACKAGE \"bpftrace-test\"
#include <bfd.h> 
#include <dis-asm.h>
int main(void) {
  bfd *abfd = bfd_openr(NULL, NULL);

  disassembler(bfd_get_arch(abfd),
               bfd_big_endian(abfd),
               bfd_get_mach(abfd),
               abfd);
  return 0;
}" LIBBFD_DISASM_FOUR_ARGS_SIGNATURE)

```

```auto
Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_02d7a/fast && gmake[1]: Entering directory '
bpftrace-0.17.1/build/CMakeFiles/CMakeTmp'
/usr/bin/gmake -f CMakeFiles/cmTC_02d7a.dir/build.make CMakeFiles/cmTC_02d7a.dir/build
gmake[2]: Entering directory 'bpftrace-0.17.1/build/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_02d7a.dir/src.cxx.o
//bin/x86_64-ftnt-linux-gnu-g++ --sysroot=//x86_64-ftnt-linux-gnu/sysroot -DLIBBFD_DISASM_FOUR_ARGS_SIGNATURE -std=c++17 -o CMakeFiles/cmTC_02d7a.dir/src.cxx.o -c target/bpftrace-0.17.1/build/CMakeFiles/CMakeTmp/src.cxx
/bpftrace-0.17.1/build/CMakeFiles/CMakeTmp/src.cxx:5:10: fatal error: bfd.h: No such file or directory
5 | #include <bfd.h>
| ^ ~~~~~~
compilation terminated.
gmake[2]: *** [CMakeFiles/cmTC_02d7a.dir/build.make:78: CMakeFiles/cmTC_02d7a.dir/src.cxx.o] Error 1

```

bfd.h header is included on target include/bfd.h path but still FindLibBfd.cmake is failing to find it.  
i passed bfd.h path to 'cmake ’ command during configure stage itself as given below.

```auto
cmake -DUSE_SYSTEM_BPF_BCC=1
-DLIBBFD_LIBRARIES="${TARGET_DESTDIR}/lib" \
       -DLIBBFD_INCLUDE_DIRS="${TARGET_DESTDIR}/include" \
...

```

But still bfd.h path is not recognized in cmake/FindLibBfd.cmake file . configure stage log is given below.

```auto
===> begin compile bpftrace-0.17.1
....
-- Found LibBpf: /target/lib
-- Found LibCereal: /target/include/cereal
-- Found BISON: /bin/bison (found version "3.8.2")
...
-- Found LibBfd: /target/lib
-- Found LibOpcodes: /target/lib
-- Performing Test LIBBFD_DISASM_FOUR_ARGS_SIGNATURE
-- Performing Test LIBBFD_DISASM_FOUR_ARGS_SIGNATURE - Failed
...

```

Any input in towards this issue , please let me kow

Regards  
Koti

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [July 9, 2023, 4:40pm UTC](https://discourse.cmake.org/t/cmake-fail-to-find-libbfd-header-file-bfd-h/8470/2 "2023-07-09T16:40:39Z")

</div>

It looks like the `check_cxx_source_compiles` is not told to _use_ the include directory for `bfd.h`. The `CMAKE_REQUIRED_INCLUDES` variable needs set to `${LIBBFD_INCLUDE_DIRS}` before that check.
