简体   繁体   中英

winsock2 redefinition Merging issues

im trying to merge 2 projects together, one being a project in openGl and one being a windows console application, with some basic winsock networking implemented. i started merging them by just inlcuding all the #include's that were in the original network program, but im getting just over 100 errors telling me that i've redefined all the structs and functions within ws2def.h and winsock.h

so these are the #includes at the to of my main.cpp

#include <windows.h>
#include <stdio.h>
#include <mmsystem.h>
#include <math.h>
#include <time.h>

#include <list>
#include <iostream>

#include <stdlib.h>
#include <string>
#include <winsock2.h>

#pragma comment(lib, "ws2_32.lib")
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN

This can prevent windows.h from including the old winsock header file.

I came across the same problem while trying to integrate a previously working live555 server with an encoder application.

Each of the libraries I was using were including winsock and winsock2 to fulfill their tasks.

I first tried with the WIN32_LEAN_AND_MEAN define but that didn't work for me.

What ended working in my case (VS 2013) was to add _WINSOCKAPI_ in Configuration Properties -> Preprocessor -> Preprocessor Definitions .

What this does is to set, project-wide, windows.h not to include winsock when it's included.

Also, as my separate programs used winsock and winsock2 I unified the code by using winsock2 for both of them.

Hope this helps someone!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM