8

I am using boost lib on Qt creator to develop an application, my platform is Windows8 MSVC2013 64.

I have two class on each I am using boost headers,

Now I need to use this class and when I include these class header from another source file I am getting the error

error WinSock.h has already been included

In my fist class I added boost header like

#define WIN32_LEAN_AND_MEAN
#include <boost/asio.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/read_until.hpp>
#include <boost/bind.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/asio/write.hpp>
#include <boost/asio/read.hpp>
#include <boost/asio/placeholders.hpp>
#include <boost/foreach.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/thread_time.hpp>
#include <boost/interprocess/ipc/message_queue.hpp>
#include <boost/interprocess/sync/interprocess_semaphore.hpp>
#include <boost/bind.hpp>

#include <boost/cstdint.hpp>
#include <boost/circular_buffer.hpp>
#include <boost/format.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>

and in second class I used the header on same way

#define WIN32_LEAN_AND_MEAN
#include <iostream>

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/thread_time.hpp>
#include <boost/interprocess/sync/interprocess_semaphore.hpp>
#include <boost/interprocess/ipc/message_queue.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/read_until.hpp>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/asio/write.hpp>
#include <boost/asio/read.hpp>
#include <boost/bind.hpp>
#include <iostream>
#include <boost/asio/placeholders.hpp>
#include <fstream>
#include <boost/cstdint.hpp>
#include <boost/circular_buffer.hpp>
#include <boost/format.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>

I already found the answer here Boost::asio winsock and winsock 2 compatibility issue but still I am having the issue.

Edit: My second class internally using the first class header, does that be the cause like multiple time including the boost headers?

I have surrounded the boost header includes with

#ifndef class_obj__1
#define class_obj__1
//boost headers
//boost headers  
#endif

Any help will be appreciated.

Thanks Haris

8
  • Are you getting the error on the first class or the second class? Jun 9, 2015 at 11:56
  • The error message is like C:\boost\boost_1_58_0\boost\asio\detail\socket_types.hpp:24: error: C1189: #error : WinSock.h has already been included
    – Haris
    Jun 9, 2015 at 12:00
  • Have you tried putting the include of <iostream> and <fstream> after all the boost headers for the second class? Jun 9, 2015 at 13:07
  • Yes I tried that too...
    – Haris
    Jun 9, 2015 at 13:11
  • 1
    if you are using visual studio enable show includes, you will find the culprits.
    – UmNyobe
    Jun 9, 2015 at 14:52

1 Answer 1

17

Move the #define WIN32_LEAN_AND_MEAN to g++ command line argument list as -DWIN32_LEAN_AND_MEAN. This helped me.
One more thing helped me is reordering #include directives to put boost includes before all others.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.