错误 C1083: 无法打开源文件:"stdafx.cpp":没有那个文件或目录。

4

我遇到了上述错误,并已经尝试了所有解决方案,但均无法解决。

这是我的stdafx.h文件。它在目标目录中,我可以看到该文件,完整路径指向那里。此外,我创建了一个win32项目。为什么我的代码不能工作?

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>



// TODO: reference additional headers your program requires here

实际代码:

// ConsoleApplication1.cpp : Defines the entry point for the console application. //
#include "stdafx.h"
#include <iostream>

int main() {    std::cout << "Hello world!" << std::endl;   return 0; }

2
无法打开源文件:“stdafx.cpp”:没有那个文件或目录。创建stdafx.cpp。或者禁用预编译头文件。并从您的项目中删除stdafx.cpp - drescherjm
似乎你的项目出了些问题。也许用一个新的Win32控制台项目重新开始会更容易些。 - drescherjm
所以我尝试查看是否可以删除源文件,然后重新添加它们。当我尝试搜索它们时,Visual Studio无法识别它们并将其显示为文件。我之前尝试过重新创建项目,但没有成功。在启动时,我选择Visual C++下的Win32控制台应用程序。 - ThisIsPavski
更新:在创建项目时,即使没有编写任何主要代码,我也会进行编译。然后我编写代码,再次编译,一切都正常运行。 - ThisIsPavski
这根本就没有任何意义。绝对不是预期的行为。我完全猜不出为什么你的编译器/系统会这样表现不正常。 - drescherjm
显示剩余3条评论
1个回答

7

记录一下,我在Windows 10的Ubuntu shell中使用git克隆repo时遇到了这个问题。

当我在Windows shell中使用git将repo克隆到另一个位置后,问题消失了,解决方案也能成功构建。

问题在于构建脚本在寻找大写字母命名的文件夹中的'stdafx.cpp'时出错(C:\GIT\LIBRARYX\SRC\),如果使用Ubuntu bash从git克隆解决方案,则该路径无法正常工作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接