如何在没有stdafx.h的情况下为跨平台应用程序运行cl.exe

时间:2020-02-08 04:28:07

标签: c++ github visual-c++ cl stdafx.h

假设我有一个简单的代码

// main.cpp

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string text = "Hello world.";
    cout<<text<<endl;
    return 0;
}

运行正常。现在,我要确保它是跨平台的。在github CI上,我在使用许多编译器进行测试时遇到了问题,但在cl.exe方面遇到困难

cl.exe /std:c++latest main.cpp

严重错误C1083:无法打开包含文件:'iostream':没有此类文件或目录

我知道这是因为Microsoft希望我在我不想做的代码的开头包含stdafx.h。我尝试了其他一些无效的工作:

  • 尝试1
cl.exe /std:c++latest /Y- main.cpp

严重错误C1083:无法打开包含文件:'iostream':没有此类文件或目录



  • 尝试2
cl.exe /std:c++latest /Yc"stdafx.pch" /Yu"stdafx.h" /FI"stdafx.h" main.cpp

严重错误C1083:无法打开预编译的头文件:'stdafx.pch':没有此类文件或目录



  • 尝试3
cl.exe /std:c++latest /Yu"stdafx.h" /FI"stdafx.h" main.cpp

严重错误C1083:无法打开预编译的头文件:'stdafx.pch':没有此类文件或目录



  • 尝试4
cl.exe /std:c++latest /Yc"stdafx.h" /FI"stdafx.h" main.cpp

严重错误C1083:无法打开包含文件:'stdafx.h':没有此类文件或目录


那么,解决方案是什么?

0 个答案:

没有答案