Page 1 of 1

Adding library to new C++ hardware plugin

Posted: Wednesday 06 May 2020 15:40
by rafal9318
Hi All,

I have a question about adding the library to CMakeLists.txt file, to corretly compile and link new hardware with Domoticz source.
I'm creating new hardware in C++, new hardware in based on Dummy hardware. I copied it and change names.
But now i need to add to this new hardware library #include <modbus/modbus.h>
This library: https://github.com/stephane/libmodbus

I put src files in ../hardware/modbus directory.

And now i need to know how to add this library to CMakeLists.txt file, to correctly compile and link library, and to use functions (for example modbus_read_bits(...) ) from modbus library in new hardware (for example in Do_Work() method).

I tried, just to add this line to CMakeLists/txt:
hardware/modbus/modbus.c

but after make i've got"
[ 12%] Building CXX object CMakeFiles/domoticz.dir/cmake_pch.hxx.gch
[ 12%] Building C object CMakeFiles/domoticz.dir/cmake_pch.h.gch
In file included from /home/pi/dev-domoticz/CMakeFiles/domoticz.dir/cmake_pch.h:4,
from <command-line>:
/home/pi/dev-domoticz/main/stdafx.h:18:10: fatal error: string: No such file or directory
#include <string>
^~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/domoticz.dir/build.make:98: CMakeFiles/domoticz.dir/cmake_pch.h.gch] Error 1
make[1]: *** [CMakeFiles/Makefile2:380: CMakeFiles/domoticz.dir/all] Error 2
make: *** [Makefile:172: all] Error 2

Please help.

Re: Adding library to new C++ hardware plugin

Posted: Wednesday 06 May 2020 20:25
by rafal9318
Okey, i found the solution.
Someone may delete topic.

Re: Adding library to new C++ hardware plugin

Posted: Wednesday 06 May 2020 20:49
by waaren
rafal9318 wrote: Wednesday 06 May 2020 20:25 Okey, i found the solution.
Someone may delete topic.
Is the solution worth to share?
Maybe other forum members don't have to search for it when they have the same question / issue.