在项目中包含.lib和标头会导致C1189 windows.h已包含错误 [英] Including .lib and headers into project causes C1189 windows.h already included error

查看:57
本文介绍了在项目中包含.lib和标头会导致C1189 windows.h已包含错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经在Visual Studio 2003 .net中编写了一个Win32控制台应用程序,该应用程序使用套接字,因此包括winsock2.h和wsock32.lib.
现在,我必须合并其他人编写的一些文件,并在我的项目设置中包含一个.lib和一些标头,以使他们的代码正常工作.我已添加到stdafx.h中的代码的标头分别称为ModuleIo.h和ApplicatioIo.h.这些标头包含许多其他标头,这些标头位于我已添加到项目设置中包含目录的目录中.但是这些都不是Windows标头-它们都是由某人提供的,并且其中包含更多的代码.

问题是我现在遇到了"C1189 windows.h已经定义"的问题.我已经在互联网上阅读了很多有关此问题的信息,但仍然找不到解决我问题的方法.我将在这里发布我的stdafx.h,但是直到合并其他人的代码和.libs时,问题才会发生.其他人似乎都可以通过在stdafx.h中重新排序其#include来解决此问题,但是我已经尝试过了(将winsock2.h放在开头或结尾),但这没有什么区别.

// stdafx.h : 
#pragma once
#include <winsock2.h>
#include <stdio.h>
#include <tchar.h>
#include <process.h> //for _beginThread
#include <iostream>
#include <stdlib.h>
#include <conio.h> //for getche()
#include <errno.h>
#include <time.h>
#include <string>
#include <sstream>
#include <stddef.h>
#include <atlbase.h> //for debug TRACE
#include <signal.h>
#include "DigiConfig.h"
#include "CardStatus.h"//for the enums E_RAD2_STATES
#include "CardBulkXfer.h"
#include "SharedMemory.h"
#include "CardInterface.h"
#include "ModuleIo.h"// this is an added header
#include "ApplicationIo.h"// this is an added header
#include "CardCtrl.h"
#include "CardThread.h"
#include "ClientHandlerThread.h"
#include "ConsoleHandler.h"
#include "CardDataWriterThread.h"
#include "CardDataHandlerThread.h"



我确实尝试将#undef _WINDOWS_放在#include"winsock2.h"之后,该错误消除了dthe错误,但是产生了一个关于对睡眠的迁移调用的新错误-它在winbase.h和atlbase.h中定义,所以我仍然包括我不应该定义的两个方法,我真的不知道下一步该怎么做.请帮忙!

解决方案

Winsock2.h 包括 Windows.h (如果尚未提供).但是最好先包含 Windows.h .

最好的方法是让Visual Studio在创建项目时生成 stdafx.h 文件.然后,在检查项目的套接字选项时,它还将包含 winsock2.h .

您可以使用这些设置创建一个新项目,然后将所有现有文件添加到新项目中.

或者,您可以在 stdafx.h 文件的顶部添加 windows.h 文件和其他必需的Windows头文件.


<当您在afxwin.h之前包含windows.h时,将发生blockquote> error C1180. ,我不知道这种情况会在您的程序中发生.

jkchan
http://cgmath.blogspot.com [ ^ ]


Hi,

I have written a Win32 console app in visual studio 2003 .net which uses sockets therefore includes winsock2.h and the wsock32.lib.

I now have to incorporate some files that someone else has written and also include a .lib and some headers in my project''s setting in order for their code to work. The headers for their code that I have added to stdafx.h are called ModuleIo.h and ApplicatioIo.h. These headers include a lot of other headers that are in the directory that I have added to the include directories in the project settings. But none of these includes are windows headers - they are all provided by someone and have more of their code in.

The trouble is I now get the "C1189 windows.h already defined" problem. I have read so much about this on the internet but I still can''t find a solution to my problem. I will post my stdafx.h here, but the problem does not occur until I incorporate somebody elses code and .libs. Everyone else seems to solve this by reordering their #includes in stdafx.h but I have tried that (putting winsock2.h at the start or end) but it makes no difference.

// stdafx.h : 
#pragma once
#include <winsock2.h>
#include <stdio.h>
#include <tchar.h>
#include <process.h> //for _beginThread
#include <iostream>
#include <stdlib.h>
#include <conio.h> //for getche()
#include <errno.h>
#include <time.h>
#include <string>
#include <sstream>
#include <stddef.h>
#include <atlbase.h> //for debug TRACE
#include <signal.h>
#include "DigiConfig.h"
#include "CardStatus.h"//for the enums E_RAD2_STATES
#include "CardBulkXfer.h"
#include "SharedMemory.h"
#include "CardInterface.h"
#include "ModuleIo.h"// this is an added header
#include "ApplicationIo.h"// this is an added header
#include "CardCtrl.h"
#include "CardThread.h"
#include "ClientHandlerThread.h"
#include "ConsoleHandler.h"
#include "CardDataWriterThread.h"
#include "CardDataHandlerThread.h"



I did try putting #undef _WINDOWS_ after the #include "winsock2.h", which remove dthe error but produced a new one about an amiguous call to Sleep - which is defined in winbase.h and atlbase.h, so I am still including two defintions of methods which i shouldn''t be and I really don''t know what to try next. Please help!

解决方案

Winsock2.h includes Windows.h if not included so far. But it is always better to have Windows.h included before.

The best way is to let Visual Studio generate a stdafx.h file upon project creation. Then it will also include winsock2.h when checking the socket options of the project.

You may create a new project with these settings and then add all your existing files to the new project.

As an alternative, you may add the windows.h file and other required windows header files on top of your stdafx.h file.


error C1180 will occur when you include windows.h before afxwin.h. , i don''t know this case happens in your program.

jkchan
http://cgmath.blogspot.com[^]


这篇关于在项目中包含.lib和标头会导致C1189 windows.h已包含错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆