New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows compilation in master #63

Closed
oldfaber opened this Issue Jun 6, 2012 · 11 comments

Comments

Projects
None yet
5 participants
@oldfaber
Contributor

oldfaber commented Jun 6, 2012

Windows connect() does not set errno, and EINPRORGESS is not defined.

The patch below fixes it.
(Is it possible to attach a file with the patch ?)

I also have many more patches.
Should I create a fork ?
I would really like to upstream the acceptable ones.

The first would be the creation of a win32 directory with a self-contained
Visual Studio Express 2008 project file to create a modbus.dll.
To create a useful DLL I need to mark the exported functions with
...
EXPORT void modbus_close(modbus_t *ctx);
...
in the headers and sources.
Obviously EXPORT is only defined under _WIN32.
Is this acceptable ?

Regards
Fabio

+++ PATCH

--- stephane-libmodbus-2dca042/src/modbus-tcp.c 2012-05-28 17:00:22.000000000 +0200
+++ p1-libmodbus/src/modbus-tcp.c 2012-06-06 15:45:20.457647000 +0200
@@ -243,7 +243,11 @@ static int _connect(int sockfd, const st
int rc;

 rc = connect(sockfd, addr, addrlen);

+#if defined(_WIN32)

  • if (rc == -1 && WSAGetLastError() == WSAEINPROGRESS) {
    +#else
    if (rc == -1 && errno == EINPROGRESS) {
    +#endif
    fd_set wset;
    int optval;
    socklen_t optlen = sizeof(optval);
@stephane

This comment has been minimized.

Show comment
Hide comment
@stephane

stephane Jun 6, 2012

Owner

I've received many mails, patches and seen forks for Visual Studio but none of them was really clean (patches as directory tarballs, forks with huge copy/paste of codes, etc) so I'll be happy if you could provide a clean solution to have Visual Studio support (DRY and thin).

Your EXPORT solution is acceptable (as extern in the past :)

For the generic errors (Unix/Windows), other libraries ZMQ (now Crossroads IO), Cairo have nice solutions to do that.

Owner

stephane commented Jun 6, 2012

I've received many mails, patches and seen forks for Visual Studio but none of them was really clean (patches as directory tarballs, forks with huge copy/paste of codes, etc) so I'll be happy if you could provide a clean solution to have Visual Studio support (DRY and thin).

Your EXPORT solution is acceptable (as extern in the past :)

For the generic errors (Unix/Windows), other libraries ZMQ (now Crossroads IO), Cairo have nice solutions to do that.

@stephane

This comment has been minimized.

Show comment
Hide comment
@stephane

stephane Jun 6, 2012

Owner

For the previous patch it will better to have something like this:

#if defined(_WIN32)
errno = CustomWSAGetLastError();
#endif
Owner

stephane commented Jun 6, 2012

For the previous patch it will better to have something like this:

#if defined(_WIN32)
errno = CustomWSAGetLastError();
#endif
@oldfaber

This comment has been minimized.

Show comment
Hide comment
@oldfaber

oldfaber Jun 6, 2012

Contributor

Then in CustomWSAGetLastError you should set errno to EINPROGRESS (not defined under Win32) to what value ?
Keeping OS portability is not easy, not nice. I think that the patch is about the minimal change you could do.
If more cases arise we could always switch to a more general solution.

How should I submit the patch for win32 DLL ?
Mail a patch ?
Create a fork ?
???

Thanks
Fabio

Contributor

oldfaber commented Jun 6, 2012

Then in CustomWSAGetLastError you should set errno to EINPROGRESS (not defined under Win32) to what value ?
Keeping OS portability is not easy, not nice. I think that the patch is about the minimal change you could do.
If more cases arise we could always switch to a more general solution.

How should I submit the patch for win32 DLL ?
Mail a patch ?
Create a fork ?
???

Thanks
Fabio

@stephane

This comment has been minimized.

Show comment
Hide comment
@stephane

stephane Jun 6, 2012

Owner

I think at something like https://github.com/crossroads-io/libxs/blob/master/src/err.cpp#L209

A fork, but please, create a dedicated branch to ease rebasing, try to create small and atomic patches (as you do until now :)

Owner

stephane commented Jun 6, 2012

I think at something like https://github.com/crossroads-io/libxs/blob/master/src/err.cpp#L209

A fork, but please, create a dedicated branch to ease rebasing, try to create small and atomic patches (as you do until now :)

@stephane stephane closed this Jun 6, 2012

@stephane stephane reopened this Jun 6, 2012

@samedsoft

This comment has been minimized.

Show comment
Hide comment
@samedsoft

samedsoft Aug 25, 2012

Hi,

Today I have downloaded libmodbus 3.1.0 and installed mingw with C, C++ Compilers and Msys Basic System, MinGW developer kit.

I went to the root folder of the project, ran "sh" command -> "./configure" -> "./make install" and spent two hours and finally found this patch..

Fixed modbus-tcp.c file as mentioned..


rc = connect(sockfd, addr, addrlen);  

#if defined(_WIN32)
if (rc == -1 && WSAGetLastError() == WSAEINPROGRESS) {  
#else 
if (rc == -1 && errno == EINPROGRESS) {         
#endif 

    fd_set wset;
    int optval;

It worked!!

I don't understand why you don't fix it on the main file and still serve a faulty file ???

I wish you guys best and thanks for the great work !!!!

Hi,

Today I have downloaded libmodbus 3.1.0 and installed mingw with C, C++ Compilers and Msys Basic System, MinGW developer kit.

I went to the root folder of the project, ran "sh" command -> "./configure" -> "./make install" and spent two hours and finally found this patch..

Fixed modbus-tcp.c file as mentioned..


rc = connect(sockfd, addr, addrlen);  

#if defined(_WIN32)
if (rc == -1 && WSAGetLastError() == WSAEINPROGRESS) {  
#else 
if (rc == -1 && errno == EINPROGRESS) {         
#endif 

    fd_set wset;
    int optval;

It worked!!

I don't understand why you don't fix it on the main file and still serve a faulty file ???

I wish you guys best and thanks for the great work !!!!

@stephane

This comment has been minimized.

Show comment
Hide comment
@stephane

stephane Nov 8, 2012

Owner

On my TODO list...

Owner

stephane commented Nov 8, 2012

On my TODO list...

@stephane stephane closed this in 34ec939 Jan 22, 2013

@stephane

This comment has been minimized.

Show comment
Hide comment
@stephane

stephane Jan 22, 2013

Owner

Quick workaround merged. Maybe one day, a guy will submit a good solution.
@samedsoft or @oldfaber, please test if you still alive after 8 months ;)

Owner

stephane commented Jan 22, 2013

Quick workaround merged. Maybe one day, a guy will submit a good solution.
@samedsoft or @oldfaber, please test if you still alive after 8 months ;)

@oldfaber

This comment has been minimized.

Show comment
Hide comment
@oldfaber

oldfaber Feb 20, 2013

Contributor

I have more or less kept this patch in my DLL for many months now.
Thank you.

Contributor

oldfaber commented Feb 20, 2013

I have more or less kept this patch in my DLL for many months now.
Thank you.

@Smatito

This comment has been minimized.

Show comment
Hide comment
@Smatito

Smatito May 29, 2013

I want to compile "libmodbus-3.0.4" on Windows8 but i can't!
i have installed MinGW and MSYS!

Smatito commented May 29, 2013

I want to compile "libmodbus-3.0.4" on Windows8 but i can't!
i have installed MinGW and MSYS!

@stephane

This comment has been minimized.

Show comment
Hide comment
@stephane

stephane Jun 4, 2013

Owner

@Smatito patch merged in master not stable branch...

Owner

stephane commented Jun 4, 2013

@Smatito patch merged in master not stable branch...

mk8 added a commit to mk8/libmodbus that referenced this issue Jan 29, 2014

Another quick workaround for deficient OS (closes #63)
It will better to code something such as:
https://github.com/crossroads-io/libxs/blob/master/src/err.cpp

I don't intend to rewrite glib neither :(
@Padmashriam

This comment has been minimized.

Show comment
Hide comment
@Padmashriam

Padmashriam Mar 7, 2018

How to connect and communicate with modbus tcp/ip in visual studio 2010 in visual c++. Share me the code for it. And do we have to add config.h header into project, since i am facing error and unable to program further. Let me know as soon as possible.
Thank you.

How to connect and communicate with modbus tcp/ip in visual studio 2010 in visual c++. Share me the code for it. And do we have to add config.h header into project, since i am facing error and unable to program further. Let me know as soon as possible.
Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment