OF 0.6 and VC++ 2010 UDP/TCP snafu


I downloaded OF 0.6 (both release and nightly build) and both pro and express versions of Visual C++ 2010. Most of the sample app code builds OK, but the UDP and TCP client/server examples have very obscure seeming build errors. What it looks like to me is that MS build system is wrapping the bind(uint, sockaddr*, uint) call that is inside of Open Frameworks xxxManager::Bind(u_short) wrapper that handles the standard inet socket call.

My current interpretation is that VC++ wants to use a templated socket obj (std::tr1::_Callable_obj<SOCKET,false>) in place of the socket ID which is just a uint really (uint_64 in this case, correct me if I’m wrong).

two other coders here are using the same source from OF and VC++ express and get no build errors. I diff’d their src with mine and the only change is some error checking. The bind() calls are identical. I get compile errors (fatal) and they do not. We looked at some obvious VC++ project property settings like paths, included libraries and nothing obvious came up.

I also tried the 2010 and 2008 versions of the OpenFrameworks .sln project files. both have the same errors. I didn’t try VC++ 2008 yet, but I saw some discussion on this forum that 2008 is better supported than 2010.

Does anyone have a clue about this? Please tell …

here’s the compiler error message:

2>c:\users\ver4\desktop\dev\openframeworks\openframeworks-openframeworks-9172441\addons\ofxnetwork\src\ofxudpmanager.cpp(97): error C2440: ‘initializing’ : cannot convert from ‘std::tr1::_Bind_fty<_Fty,_Ret,_BindN>’ to ‘int’
2> with
2> [
2> _Fty=SOCKET,
2> _Ret=std::tr1::_Notforced,
2> _BindN=std::tr1::_Bind2<std::tr1::_Callable_obj<SOCKET,false>,sockaddr *,unsigned int>
2> ]
2> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

So I found a clue in one of the other threads of this forum. Here’s the fix.

bind() as we all know and love is ancient C code from the days of green screens before GUIs or the internet. It is still the same code 40 years later. BUT the world has changed and in particular we have C++ namespaces. What happened is that VC++ was wrapping bind() in some namespace cast to an MFC or other Microsoft specific version of bind(), no doubt so they can automatically warn you if you are about to do something they think is dangerous, like visit the Apple or Google website.

changed bind() to ::bind() . That’s all. Adding the :: strips off any implicit namespace that is active, and sends bind() back to the global (i.e. EXTERN “C”) namespace.