Skip to content

Getting started


From packages

On Linux, a libmodbus package is provided for the following distributions:

On MacOS, the package is available via Homebrew brew install libmodbus.

Compilation from official releases

You can compile libmodbus from tarball releases by downloading the latest stable release.

The official tarball to use is the asset with a icon.

A C toolchain should be installed in your environment:

make install

For Visual Studio, set your platform to x64 and make sure your set these settings in the project property pages:

  • General / Project Defaults / Configuration Type, Dynamic Library (.dll)
  • Linker / Input / Additional Dependencies, ws2_32.lib


All version changes are described at GitHub releases.

Code Sample

#include <stdio.h>
#include <modbus.h>

int main(void) {
  modbus_t *mb;
  uint16_t tab_reg[32];

  mb = modbus_new_tcp("", 1502);

  /* Read 5 registers from the address 0 */
  modbus_read_registers(mb, 0, 5, tab_reg);


To compile this snippet, you can pass the header and library parameters to your C compiler (gcc, llvm, ...) with pkg-config --cflags --libs libmodbus:

cc hello.c `pkg-config --cflags --libs libmodbus`


Starting from libmodbus v3.1.8, the documentation is built by Material for mkdocs.

The new documentation is unified for all releases, changes and additions to each version are indicated. The documentation is updated at each release.

If you need to read the old documentation, the format of the old URL is where v3.1.7 can be replaced by the version you're looking for.