WinSock.h error already included Boost Windows Qt

I use boost lib to create Qt for application development, my platform is Windows8 MSVC2013 64.

I have two classes on each I use boost headers,

Now I need to use this class, and when I include this class header from another source file, I get an error

error WinSock.h has already been included 

In my first class, I added a 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 the second grade I used the header in the 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 had a problem.

Edit: My second class internally using the first class header, does this cause multithreading, including forcing headers?

I surrounded the boost header containing

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

Any help would be appreciated.

Thanks Haris

+6
source share
1 answer

Move the command line argument list #define WIN32_LEAN_AND_MEAN to g ++ as -DWIN32_LEAN_AND_MEAN . It helps me. One more thing helped me reorder the #include directives to include boost in the list before everyone else.

+11
source

Source: https://habr.com/ru/post/988784/


All Articles