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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With