简体   繁体   English

winsock2重新定义合并问题

[英]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. 我试图将2个项目合并到一起,一个是openGl中的项目,另一个是Windows控制台应用程序,并实现了一些基本的winsock网络。 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 我通过合并原始网络程序中的所有#include来开始合并它们,但是我收到了100多个错误,告诉我我已经在ws2def.h和winsock.h中重新定义了所有结构和函数。

so these are the #includes at the to of my main.cpp 所以这些是我main.cpp的#includes

#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. 这可以防止windows.h包含旧的winsock头文件。

I came across the same problem while trying to integrate a previously working live555 server with an encoder application. 尝试将以前工作的live555服务器与编码器应用程序集成时遇到了相同的问题。

Each of the libraries I was using were including winsock and winsock2 to fulfill their tasks. 我使用的每个库都包括winsock和winsock2来完成其任务。

I first tried with the WIN32_LEAN_AND_MEAN define but that didn't work for me. 我首先尝试使用WIN32_LEAN_AND_MEAN定义,但这对我不起作用。

What ended working in my case (VS 2013) was to add _WINSOCKAPI_ in Configuration Properties -> Preprocessor -> Preprocessor Definitions . 在我的情况下(VS 2013),最终的工作是在配置属性->预处理程序->预处理程序定义中添加_WINSOCKAPI_

What this does is to set, project-wide, windows.h not to include winsock when it's included. 这是在整个项目范围内设置windows.h,但不包括winsock。

Also, as my separate programs used winsock and winsock2 I unified the code by using winsock2 for both of them. 另外,由于我的单独程序使用了winsock和winsock2,因此我对winsock2和winsock2都使用了统一代码。

Hope this helps someone! 希望这对某人有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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