#pragma warning(disable: 4786)

WOOHOO!

I have successfully ported my Linux code to Windows.
My application (for time-dependent isosurface extraction and rendering) uses VTK for the visualisation, FLTK for the user-interface, and pthreads for multi-threading.

Well, the first two are cross-platform toolkits, so no problem getting them compiled under Windows. But POSIX threads… nope… So I had to try something else.


Boost is a large collection of portable C++ libraries, among which also a Threads library. I have compiled this both under Linux and Windows, and succeeded in converting all uses of pthread_t into boost::thread, pthread_mutex_t into boost::mutex and pthread_cond_t into boost::condition.

By the way, I also used the Boost Timer library, because the gettimeofday() function from <sys/time.h> also doesn’t exist on Windows.

Of course, there are a lot more problems trying to port source code to Windows. For example, I found out that the copy_n function, which is available on my Linux machine (in the <algorithm> header file), is not available on Windows. It’s “an SGI extension; it is not part of the C++ standard.”

Of course, the __PRETTY_FUNCTION__ identifier is strictly gcc, so not available in Windows. If anyone knows of an equivalent, please let me know.

Some more weird things happen with the STL vector’s assign and insert functions. I have two classes A and B, where an object of type A can be constructed from an object of type B:

A::A(const B& b);

So, if I want to create a vector of A objects from a vector of B objects I want to do something like:

a.insert(a.end(), b.begin(), b.end());     // or
a.assign(b.begin(), b.end());

It works perfectly under Linux, but on Windows it doesn’t even compile, at least with my Microsoft Visual C++ 6.0 compiler.
For the insert, I get an error C2664: “cannot convert parameter 2 from ‘class B *’ to ‘unsigned int’”.
It’s trying the wrong function! There are two versions of insert (see here), the first one taking two iterators to specify the range, and the second one taking an integer and a reference to an object. Oh well, if you look on that page, you’ll see that the first version “relies on member template functions, which at present (early 1998) are not supported by all compilers.” *SIGH*

We’re not there yet!
If you want to compile your project without warnings, you may have to add a

#pragma warning(disable: 4786)

before any (STL) include files, or else you’ll see something like this:


"warning C4786: 'std::reverse_iterator<std::vector<A,std::allocator<A> > const *,std::vector<A,std::allocator<A> >,std::vector<A,std::allocator<A> > const &,std::vector<A,std::allocator<A> > const *,int>' : identifier was truncated to '255' characters in the debug information".

Finally, if you get everything compiled without errors or warnings, you might run into some linking problems. For example, I saw this:

LINK : warning LNK4098: defaultlib "MSVCRT" conflicts with use of other libs; use /NODEFAULTLIB:library
fltk.lib(Fl_x.obj) : error LNK2001: unresolved external symbol ___WSAFDIsSet@8
fltk.lib(Fl_x.obj) : error LNK2001: unresolved external symbol _select@20
fltkd.lib(Fl_x.obj) : error LNK2001: unresolved external symbol __imp___TrackMouseEvent@4

The first one you can get rid of by just telling the linker to ignore msvcrt.lib. See the MSDN Library for more information.

The other errors have to do with missing libraries for FLTK. You need wsock32.lib and comctl32.lib.
Just Google for ___WSAFDIsSet@8 and you’ll find some solutions.
All you have to do (if you use CMake), is edit your CMakeLists.txt and add

IF(WIN32)
LINK_LIBRARIES(wsock32 comctl32)
ENDIF(WIN32)

And that’s it! It works! Hurray!
Here is the evidence:
TIER MSVC

Tags: , , , , , , , , ,

Friday, July 2nd, 2004 Computing

5 Comments to #pragma warning(disable: 4786)

  1. By using SCons, you don’t even have to keep your Windows and Linux project files/build scripts in sync :)

    Maybe __FUNCTION__ or __FUNCSIG__ can serve as a __PRETTY_FUNCTION__ replacement (or am I missing something ?).

    We had success in porting POSIX threads from Linux to Windows using Ptreads-Win32 (but using Boost is probably better because you get much more).

  2. goof on July 5th, 2004
  3. Oops – I see that you’re already using CMake. Please ignore my SCons comments – I have no intention of provoking a flamewar :)

  4. goof on July 5th, 2004
  5. Still waiting for that OS X port… :-D

  6. Vincent on July 8th, 2004
  7. Well, Vincent, I don’t have a Mac, but if you want… feel free to port my code to OS X – it should work!
    VTK, FLTK and CMake are all cross-platform, and also Boost is designed to be portable, so… be my guest! And please let me know your results! :-)

  8. Benjamin on July 13th, 2004
  9. __FUNCTION__ or __FUNCSIG__ are only available in VC > 2003 . So, there is no solution that i know for VC 6

  10. chowette on March 29th, 2006

Leave a comment

Search

 

Categories

Archives

Creative Commons License
This work is licensed under a
Creative Commons License.