【发布时间】:2016-08-07 13:20:47
【问题描述】:
我正在尝试让我的学校作业在 GCC 和 MS VS 环境中工作,但由于某种原因,它无法在 MS VS 中编译...
错误是:
警告 C4627:“#include”:在查找预编译标头使用时跳过 - 将指令添加到“Stdafx.h”或重建预编译标头
或
意外的#endif(#include "Stdafx.h" 之后的那个)
或
当我将“Stdafx.h”标题放在第一行时,它的行为就像没有 stdio 并且所有内容(HANDLE、int 等)都是非法声明。
#include <stdio.h>
#include <stdlib.h>
#ifdef _MSC_VER
#include "Stdafx.h"
#include <windows.h>
#endif // _MSC_VER
#ifdef __GNUC__
#include <unistd.h>
#endif // __GNUC__
#ifdef _MSC_VER
int main ()
{
printf("___MS VS Studio/Express compiler___\n");
/*some stuff here*/
return 0;
}
#endif //_MSC_VER
#ifdef __GNUC__
int main()
{
printf("___GCC compiler___\n");
/*some other stuff here*/
return 0;
}
#endif // __GNUC__
它在 GCC 上运行良好,我怀疑它与 MS VS 中 #ifdef 条件中的 #includes 有关,但我不知道如何正确地做到这一点..
任何人都可以纠正我如何使其正常工作吗? 欢迎任何有用的建议,谢谢!
【问题讨论】:
-
请出示您的“Stdafx.h”文件
-
// stdafx.cpp : 仅包含标准的源文件包含 // project.pch 将是预编译的头文件 // stdafx.obj 将包含预编译的类型信息 #include " stdafx.h" // TODO:在 STDAFX.H 中引用您需要的任何其他头文件 // 而不是在此文件中
标签: c visual-studio gcc