libmodbus icon indicating copy to clipboard operation
libmodbus copied to clipboard

Fix of modbus.vcproj + AppVeyor Windows CI / Binaries Support

Open csachs opened this issue 8 years ago • 8 comments

I hoped to find 'official' Windows binaries somewhere, but unfortunately they don't seem to exist? As building binaries with MSVC under Windows is often quite… unpleasant, and I need reproducible builds of libmodbus, I've checked free cloud CI service AppVeyor (think: Travis for Windows). And some ~50 builds and an afternoon later I came up with the attached appveyor.yml.

I've found modbus.vcproj in a broken state, the settings for the 64 bit build were wrong (Application output type instead DLL), and ws2_32.lib dependencies were missing. I've fixed it as well. (I did not try it with a GUI version of MSVC, but it works for the AppVeyor builds, so I guess it's syntactically fine).

If these additions are good to be added, you could couple the libmodbus repository with AppVeyor, and benefit from automatic builds. As a nice upside, AppVeyor seems to host the produced artifacts for each build then: (With a little more work they could be pushed somewhere else as well).

See e.g. AppVeyor CI'ing my libmodbus fork: https://ci.appveyor.com/project/csachs/libmodbus And the Artifacts (ZIP Archives containing the .dll, .lib, modbus.h etc.) https://ci.appveyor.com/project/csachs/libmodbus/build/job/1774gfinhq88vlv5/artifacts (32 bit) https://ci.appveyor.com/project/csachs/libmodbus/build/job/jnhrgumj1gojrnxs/artifacts (64 bit)

Best regards, Christian

csachs avatar Jul 04 '17 21:07 csachs

I had the same problem, but I want to use with Qt, not VS. I am having a hard time to compile it on Windows.

I manage to compile using your files (they are in C:\Users\IST\Documents\los\modbus\libs) with this line command g++ -o main libs\main.cpp -IC:\Users\IST\Documents\los\modbus\libs -LC:\Users\IST\Documents\los\modbus\libs -lmodbus, but it showed this error:

C:\Users\IST\Documents\los\modbus\libs/stdint.h:34:2: error: #error "Use this header only with Microsoft Visual C++ compilers!"
 #error "Use this header only with Microsoft Visual C++ compilers!"
  ^

So I changed to g++ -o main libs\main.cpp -LC:\Users\IST\Documents\los\modbus\libs -lmodbus and it worked. But I am thinking if it will really work. Can you help me in some way?

The code I'm trying to compile is the code provided in libmodbus.org, with an additional print just to see something happen when running.

EDIT: I just find out that Qt has something about Modbus, so I'm probably migrating to that. Sorry :)

losoliveirasilva avatar Jul 31 '17 19:07 losoliveirasilva

@losoliveirasilva stdint.h should be included in all MinGW distributions, it's only needed for older versions of VC which lack it. As such, it should compile/work with MinGW. In general, MinGW has less of a problem with VC-compiled DLLs, while the opposite is often not true. If you wanted to compile a native MinGW version, I assume you could using MSYS and the normal libmodbus build instructions. But in general yes, if you want to use Qt anyways and Qt already provides Modbus functionality, it's probably the easiest to use that.

csachs avatar Aug 01 '17 07:08 csachs

@csachs This was very useful. I could successfully compile x64 with Visual Studio 2012. So, yes it does work with Visual Studio as well. Thank you.

bellekci avatar Nov 02 '17 14:11 bellekci

@csachs Hey Christian, unfortunately its not possible to download the artifacts directly (for some reason) from appveyor, could you upload them somewhere (I think they are only available to the project owner)? Because i also have problems importing the VC project into Visual Studio 2017, it definitely is destroying some information (for example x64 isn't even available as a platform). That would be much appreciated!

edit: I also suspect that your x64 project will have the same problem my adaptation of the VS project of stephane had, since you also get a lot of "inconsistent dll linkage" there.

wlfbck avatar Dec 14 '18 13:12 wlfbck

@wlfbck Hi, the problem is that AppVeyor has introduced a time limit for artifact storage: They are deleted after 6 months now. I've rebuilt the commit, the new links are:

https://ci.appveyor.com/project/csachs/libmodbus/builds/21057857/job/ctfwiyh9ytt0tqhi/artifacts (32 bit) https://ci.appveyor.com/project/csachs/libmodbus/builds/21057857/job/002oa9ip4q8g1eoi/artifacts (64 bit)

These links are a "workaround" for 6 months now… I haven't looked into building libmodbus for some time now, and am currently rather busy. I do not intend to host Windows builds in the long term, as such I hope that the project maintainer might do that (as building via AppVeyor/CI can be automated).

csachs avatar Dec 17 '18 10:12 csachs

@csachs I just merged another version of Appveyor, could look at it, please? https://github.com/stephane/libmodbus/blob/master/.appveyor.yml and rebase your PR if required. Thank you.

stephane avatar Aug 02 '19 15:08 stephane

While it was a bit of work, I've merged the two approaches. The AppVeyor configuration now runs tests under cygwin, and builds DLLs using MSVC, aswell. (Sadly the cygwin in the VS13 image doesn't work, and msbuild in the VS17 images doesn't, so the configuration is somewhat more complex) All binaries (cygwin/msvc for 32/64 bit) are exported as ZIP files, and can be downloaded from AppVeyor.

csachs avatar Aug 06 '19 16:08 csachs

Please excuse my belated reply, I was on vacation. I've pushed new commits. The tests seem to have some stochasticity to them, as they work sometimes and fail sometimes for Travis CI / cygwin.

csachs avatar Aug 19 '19 11:08 csachs