# Include the bcm2835 library for the Raspberry Pi

**URL:** <https://discourse.cmake.org/t/include-the-bcm2835-library-for-the-raspberry-pi/2396>\
**Category:** Code\
**Created:** [December 18, 2020, 7:51pm UTC](https://discourse.cmake.org/t/include-the-bcm2835-library-for-the-raspberry-pi/2396 "2020-12-18T19:51:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Krakert](https://discourse.cmake.org/user_avatar/discourse.cmake.org/krakert/32/1039_2.png) [@Krakert](https://discourse.cmake.org/u/Krakert)\
**Post date:** [December 18, 2020, 7:51pm UTC](https://discourse.cmake.org/t/include-the-bcm2835-library-for-the-raspberry-pi/2396/1 "2020-12-18T19:51:33Z")

</div>

Hello everyone, I`m new to this forum and CMake.

For a school project, we are working with c++.

And we are using CMake to link and build the files.  
Now a few months in the project I’m working with the MLX90461 IR camera.  
I’m using the following GitHub project to make the IR camera [https://github.com/Arthav24/MLX90641](https://github.com/Arthav24/MLX90641)

In this GitHub project, there is a simple example code which can be run with the makefile.  
But I want to include the example code to the CMakeLists.  
I have the following CMakeFile.txt file

```auto
cmake_minimum_required(VERSION 3.10)

set(CMAKE_CXX_STANDARD 20)

project(robot-on-wheels)

# MAIN CPP FILE TO RUN #
add_executable(robot main.cpp) # Ignore this file for now, this one works great!
add_executable(camera MLX90641/Examples/print_grid.cpp)

# Add files to libray for the MLX90641 #
add_library(mlx90641
        MLX90641/MLX90641_API.cpp
        MLX90641/MLX90641_I2C_Driver.cpp)

# MLX90641 #
target_link_libraries(mlx90641 -lm)
target_link_libraries(mlx90641 -lbcm2835)

add_definitions(-I/usr/include -L/usr/lib -lwiringPi)

target_link_libraries(camera mlx90641)

```

When I run the exmaple code with the make file it runs:  
`g++ -IHeaders/ MLX90641_API.cpp MLX90641_I2C_Driver.cpp Examples/print_grid.cpp -o printgrid -lm -lbcm2835`

And it links the bcm2835 library. But somehow I can’t get it to work via the CMakeLists.txt file.  
In bouth the `MLX90641_API.cpp` and `print_grid.cpp` There is a `#include <bcm2835.h>` without a error of CLion.

I have installed the bcm2835 file based on this anwers on the Raspberry pi forum:  
[https://www.raspberrypi.org/forums/viewtopic.php?t=15892#p1299984](https://www.raspberrypi.org/forums/viewtopic.php?t=15892#p1299984)

Is there somebody here that could me out with this? I’m stuck at this problem for 3 days now.

---

<div class="post-metadata">

**Author:** ![Krakert](https://discourse.cmake.org/user_avatar/discourse.cmake.org/krakert/32/1039_2.png) [@Krakert](https://discourse.cmake.org/u/Krakert)\
**Post date:** [December 24, 2020, 9:38am UTC](https://discourse.cmake.org/t/include-the-bcm2835-library-for-the-raspberry-pi/2396/2 "2020-12-24T09:38:53Z")

</div>

Is there nobody out there that could help me out with linking the BCM2835 library?

---

<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:** [January 4, 2021, 6:51pm UTC](https://discourse.cmake.org/t/include-the-bcm2835-library-for-the-raspberry-pi/2396/3 "2021-01-04T18:51:47Z")

</div>

> [@Krakert](#):
>
> ```auto
> add_definitions(-I/usr/include -L/usr/lib -lwiringPi)
> 
> ```

These are not definitions. I expect you want `target_include_directories`, `target_link_directories`, and `target_link_libraries` for the three flags here.
