我昨天发过一个类似的帖子:我建了一个工作区,这个工作区包含两个项目:一个是Console的Server端,一个是Dialog的Client端。 文件结构如下: public.h
public.cppServer目录 [ 控制台程序 ]
Server.cpp 包含public.h
Client目录 [ 对话框程序 ]
stdAfx.h 包含public.h
public.h文件是服务器端和客户端都需要用到的一些结构和函数。当public.cpp文件不包含stdAfx.h时控制台程序包含public.h没问题,但此时把public.h包含到对话框的stdAfx中编译会出现问题。当public.cpp中包含stdAfx.h时则对话框程序编译正常,控制台程序却不行(一、控制台程序不需要stdAfx文件,二、就算加了对话框中的stdAfx.h文件,但此时对话框编译就会出现问题了,因为此时的相对路径已经改变了)。
请问大家又没有什么好的解决方法?
public.cppServer目录 [ 控制台程序 ]
Server.cpp 包含public.h
Client目录 [ 对话框程序 ]
stdAfx.h 包含public.h
public.h文件是服务器端和客户端都需要用到的一些结构和函数。当public.cpp文件不包含stdAfx.h时控制台程序包含public.h没问题,但此时把public.h包含到对话框的stdAfx中编译会出现问题。当public.cpp中包含stdAfx.h时则对话框程序编译正常,控制台程序却不行(一、控制台程序不需要stdAfx文件,二、就算加了对话框中的stdAfx.h文件,但此时对话框编译就会出现问题了,因为此时的相对路径已经改变了)。
请问大家又没有什么好的解决方法?
public.cpp
-----------------------------------------------------------------#include "public.h"
#if defined(_WINDOWS_)
#include "StdAfx.h"
#endif错误:public.cpp(4) : fatal error C1020: unexpected #endif
#include "stdafx.h"
#endif
1. public.h 中 宏定义:#ifndef _PUBLIC_H
#define _PUBLIC_H..... //public.h 的内容#endif //这是文件最后一句2. public.cpp 里面 include "public.h"
3. 把 public.h public.cpp 都通过 过程菜单 添加到工程
4. 在Server.cpp 和 stdafx.h 2个文件里 都 include "public.h"
5. 设置Link 选项: /Force==== OK 啦 ========
http://topic.csdn.net/t/20030326/15/1579565.html