| 1 | # Instructions to compile on Windows |
| 2 | |
| 3 | ## Create a new Visual Studio project with the library included |
| 4 | |
| 5 | Download the latest version of libmodbus source code from Github |
| 6 | `https://github.com/stephane/libmodbus` -> Code -> Download ZIP. |
| 7 | |
| 8 | Once the archive is decompressed, launch a Windows terminal (`cmd`) in |
| 9 | `src/win32` directory and run `cscript configure.js`. |
| 10 | |
| 11 | 1. copy the file `config.h` from `src/win32` to `src`. |
| 12 | 2. create a new 'Console App' project under Visual Studio. |
| 13 | 3. create a new directory called `libmodbus` inside your VS project (same level |
| 14 | as the `.vcxproj` file). |
| 15 | 4. copy all `*.c` and `*.h` from libmodbus `src` in the new `libmodbus` folder |
| 16 | of your VS project. |
| 17 | 5. copy `modbus.rc` in your VS project (same level as the `.vcxproj` file). |
| 18 | 6. drag and drop `libmodbus/*.c` files (4) in *Solution Explorer -> Source Files*. |
| 19 | 7. drag and drop `libmodbus/*.h` files (8) in *Solution Explorer -> Header Files*. |
| 20 | 8. drag and drop `modbus.rc` file in *Solution Explorer -> Resource Files*. |
| 21 | 9. check path is `#include "modbus-version.h"` in `modbus.rc`. |
| 22 | 10. in the **Property Pages** of the project *Configuration Properties -> C/C++ |
| 23 | -> General -> Additional Include Directories*, add `libmodbus` folder. |
| 24 | 11. in the **Property Pages** of the project *Configuration Properties -> |
| 25 | Resources -> Additional Include Directories*, add `libmodbus` folder. |
| 26 | 12. in the **Property Pages** of the project *Configuration Properties -> Linker |
| 27 | -> Input*, define `ws2_32.lib`. |
| 28 | 13. if required, add `_CRT_SECURE_NO_WARNINGS` to *C/C++ -> Preprocessor -> |
| 29 | Preprocessor Definitions*. |
| 30 | |
| 31 | ## Create a libmodbus DLL |
| 32 | |
| 33 | This directory contains the project file for Visual Studio to build `modbus.dll` |
| 34 | and import library `modbus.lib`. |
| 35 | |
| 36 | In the Windows terminal, run `cscript configure.js` to generate: |
| 37 | |
| 38 | - `config.h` |
| 39 | - `modbus-version.h` are generated using configure.js. |
| 40 | |
| 41 | To write... |