Commit 9a7ea129283a8a69de0f36572ad2f9261d0003ac

Authored by Stéphane Raimbault
1 parent ae015c96

Instructions to build libmodbus in a VS project

Tested with Visual Studio 2022.
README.md
... ... @@ -38,8 +38,8 @@ date (run `ldconfig` as root if required).
38 38 The library provides a *libmodbus.pc* file to use with `pkg-config` to ease your
39 39 program compilation and linking.
40 40  
41   -If you want to compile with Microsoft Visual Studio, you need to install
42   -<https://github.com/chemeris/msinttypes> to fill the absence of stdint.h.
  41 +If you want to compile with Microsoft Visual Studio, you should follow the
  42 +instructions in `./src/win32/README.md`.
43 43  
44 44 To compile under Windows, install [MinGW](http://www.mingw.org/) and MSYS then
45 45 select the common packages (gcc, automake, libtool, etc). The directory
... ...
src/win32/README.md 0 → 100644
  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...
... ...
src/win32/README.win32 deleted
1   -Intro
2   ------
3   -
4   -This directory contains the project file for Visual Studio 2008 to build
5   -modbus.dll and the import library modbus.lib.
6   -
7   -The project file looks for D:/include/msvc_std to find stdint.h.
8   -See ../../README.md file.
9   -
10   -config.h and ../modbus-version.h are generated using configure.js.
11   -
12   -Run
13   - cscript configure.js
14   -or
15   - wscript configure.js
16   -or
17   - double click configure.js to generate these files.
18   -
19   -To get project file for Visual Studio 2005 open copy of file modbus.vcproj in
20   -editor and change attribute `Version` of `VisualStudioProject` tag to "8,00".
21 0 \ No newline at end of file