# adding libmodbus to CMakeLists.text file

**URL:** <https://discourse.cmake.org/t/adding-libmodbus-to-cmakelists-text-file/7681>\
**Category:** Code\
**Created:** [March 15, 2023, 5:30am UTC](https://discourse.cmake.org/t/adding-libmodbus-to-cmakelists-text-file/7681 "2023-03-15T05:30:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob\_Thomas](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bob_thomas/32/3258_2.png) [@Bob\_Thomas](https://discourse.cmake.org/u/Bob_Thomas)\
**Post date:** [March 15, 2023, 5:30am UTC](https://discourse.cmake.org/t/adding-libmodbus-to-cmakelists-text-file/7681/1 "2023-03-15T05:30:08Z")

</div>

Hello,

I am working on a C++ application that will run on Ubuntu 22.04. I am using Jetbrain’s C/C++ IDE called “CLion”. My application is working fine and now I wish to incorporate libmodbus into it. However, I don’t know the necessary commands needed to add libmodbus to my CMakeLists.text file. I would really appreciate some basic assistance on how to do it, so that I can can begin developing my modbus-TCP communications.

Thus far I have performed the following:

I downloaded libmodbus-3.1.10.tar.gz inside my home directory.

I created a directory called “Dev” inside my home directory.

Then I extracted libmodbus-3.1.10.tar.gz inside my “Dev” directory thus creating my “libmodbus-3.1.10” directory tree.

Inside my “libmodbus-3.1.10” directory I created a directory called “MyBuild”.

Then I went to my “MyBuild” directory and ran the following:

…/configure  
sudo make  
sudo make install

Next I created a new test project inside CLion. Inside the project tree under External Libraries -\>Header Search Path -\>include (library root)-\>modbus are the following 4 header files (modbus.h, modbus-rtu.h, modbus-tcp.h, modbus-version.h).

Then I added the code sample from hello.c from [libmodbus.org](http://libmodbus.org)’s website. However, I get the following errors: undefined reference to ‘modbus\_connect’, ‘modbus\_read\_registers’, ‘modbus\_close’, and ‘modbus\_free’.

I can see that it can’t find the library. So would you please tell me what are the commands I need to add to my CMakeLists.txt file, so that I can use the libmodbus library in my project? I know that there are only several commands that need to be added, but I am not sure what they are.

Thanks in advance, Bob
