ofxLaser compile errors on Visual Studio - seems like winsock2.h is included twice

Hi everyone,

I’m struggling to get ofxLaser compiling on Windows (I don’t use the platform but it’s important that my laser add-on works on it).

For some reason winsock2.h and other external dependencies are included both in the openframeworks lib project and the ofapp project which causes many compilation failures. How do files even get in the external dependencies folder? Is it automatic?

Any pointers would be gratefully received. Visual Studio is a complete mystery to me haha

Seb

(cc @DANtheMAN )

If you want to play along (!) it’s happening on the dev branch of ofxLaser https://github.com/sebleedelisle/ofxLaser/tree/dev (weirdly the main branch compiles OK from what I hear)

Hey @seb_ly!

Could you share the actual error logs / messages.
That could provide some insight into the issue.

I am guessing maybe Poco includes Winsock2.h via Windows.h and ofxNetwork is also doing the same?

This seems like it might be related:

Without the error logs though its hard to tel.

Cheers!
Theo

Thanks @Theo, that’s a good lead, I’ll check Poco as I think I’m including it. Error log is here (google sheet)

been diff’ing the code and looking for anything that brings in the network

I think it might be here Comparing main...dev · sebleedelisle/ofxLaser · GitHub where the Windows.h is included after the Poco Network stuff

that’s not it
compiling with /P leads to the following

1>ofxLaserScannerSettings.cpp
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\shared\ws2def.h(103): warning C4005: 'AF_IPX': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(457): note: see previous definition of 'AF_IPX' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\shared\ws2def.h(144): warning C4005: 'AF_MAX': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(476): note: see previous definition of 'AF_MAX' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\shared\ws2def.h(187): warning C4005: 'SO_DONTLINGER': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(399): note: see previous definition of 'SO_DONTLINGER' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\shared\ws2def.h(577): warning C4005: 'IN_CLASSA': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(284): note: see previous definition of 'IN_CLASSA' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\shared\ws2def.h(583): warning C4005: 'IN_CLASSB': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(290): note: see previous definition of 'IN_CLASSB' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\shared\ws2def.h(589): warning C4005: 'IN_CLASSC': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(296): note: see previous definition of 'IN_CLASSC' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\shared\ws2def.h(600): warning C4005: 'INADDR_ANY': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(301): note: see previous definition of 'INADDR_ANY' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\shared\ws2def.h(602): warning C4005: 'INADDR_BROADCAST': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(303): note: see previous definition of 'INADDR_BROADCAST' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock2.h(156): warning C4005: 'FD_CLR': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(94): note: see previous definition of 'FD_CLR' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock2.h(171): warning C4005: 'FD_SET': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(99): note: see previous definition of 'FD_SET' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock2.h(517): warning C4005: 'SOMAXCONN': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(541): note: see previous definition of 'SOMAXCONN' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock2.h(552): warning C4005: 'FD_READ': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(559): note: see previous definition of 'FD_READ' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock2.h(555): warning C4005: 'FD_WRITE': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(560): note: see previous definition of 'FD_WRITE' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock2.h(558): warning C4005: 'FD_OOB': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(561): note: see previous definition of 'FD_OOB' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock2.h(561): warning C4005: 'FD_ACCEPT': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(562): note: see previous definition of 'FD_ACCEPT' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock2.h(564): warning C4005: 'FD_CONNECT': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(563): note: see previous definition of 'FD_CONNECT' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock2.h(567): warning C4005: 'FD_CLOSE': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(564): note: see previous definition of 'FD_CLOSE' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\shared\ws2ipdef.h(135): warning C4005: 'IP_TOS': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(349): note: see previous definition of 'IP_TOS' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\shared\ws2ipdef.h(136): warning C4005: 'IP_TTL': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(348): note: see previous definition of 'IP_TTL' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\shared\ws2ipdef.h(137): warning C4005: 'IP_MULTICAST_IF': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(343): note: see previous definition of 'IP_MULTICAST_IF' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\shared\ws2ipdef.h(138): warning C4005: 'IP_MULTICAST_TTL': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(344): note: see previous definition of 'IP_MULTICAST_TTL' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\shared\ws2ipdef.h(139): warning C4005: 'IP_MULTICAST_LOOP': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(345): note: see previous definition of 'IP_MULTICAST_LOOP' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\shared\ws2ipdef.h(140): warning C4005: 'IP_ADD_MEMBERSHIP': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(346): note: see previous definition of 'IP_ADD_MEMBERSHIP' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\shared\ws2ipdef.h(141): warning C4005: 'IP_DROP_MEMBERSHIP': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(347): note: see previous definition of 'IP_DROP_MEMBERSHIP' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\shared\ws2ipdef.h(142): warning C4005: 'IP_DONTFRAGMENT': macro redefinition (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)
1>c:\program files (x86)\windows kits\10\include\10.0.19041.0\um\winsock.h(350): note: see previous definition of 'IP_DONTFRAGMENT' (compiling source file ..\..\..\addons\ofxLaser\src\core\ofxLaserManagerBase.cpp)

is the include log

from an old post on the net
This problem is caused when including <windows.h> before <winsock2.h> . Try arrange your include list that <windows.h> is included after <winsock2.h> or define _WINSOCKAPI_ first:

Thanks @DANtheMAN, I’ve narrowed it down to the etherdream code so I think I’m close. I’m manually including the poco network source there in ofxLaserDacEtherdream.h so I’m pretty sure that must be the issue. I’ll continue the hunt tomorrow.

OK so as soon as I include any Poco files, I get the errors. Is there another way I should be including Poco? At the moment I’m using :

#include "Poco/Net/StreamSocket.h"

And as soon as I do that I get the errors. Some kind of clash with ofxNetwork? Any ideas?

Thanks for your help so far!

Ok so further discoveries… although the dev branch compiles when I remove those poco includes there must be more at play. Because the main branch also has those includes but that compiles.

The search continues…

For anyone still following, the good news is that I fixed the problem! The bad news is that I don’t understand why what I did fixed it. There was an #include “ofxNetwork.h” in a file that wasn’t using it (one of the USB DAC files). I’d commented it out a few months ago because I thought it wasn’t needed. And indeed it shouldn’t be needed as it’s not used at all in that class!

Anyway, it’s fixed at least. :sweat_smile: Thanks for all your help on this journey

(fao @DANtheMAN )