[C++] error: File cannot be found

  • Context: C/C++ 
  • Thread starter Thread starter happysauce
  • Start date Start date
  • Tags Tags
    Error File
Click For Summary

Discussion Overview

The discussion revolves around issues encountered while programming in C++ using Visual Studio 2010, specifically focusing on project structure, function definitions, and compilation errors. Participants explore the implications of having multiple main functions and the organization of code within a project.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant describes a compilation error when trying to run a C++ program, noting that the program initially worked but later produced an error indicating the executable could not be found.
  • Another participant suggests that having two main() functions in a project could lead to a linking error, implying that this might be the cause of the issue.
  • The original poster mentions resolving the issue by creating separate projects for each code segment, asking whether it is possible to have multiple functions without a main function in a single project.
  • A later reply clarifies that a C++ program must contain one main() function as the entry point, but other functions can be named freely within the same project.

Areas of Agreement / Disagreement

Participants generally agree on the necessity of having a single main() function in a C++ project, but there is a discussion about the organization of code and the implications of having multiple functions without a main function.

Contextual Notes

There are unresolved questions regarding project structure and the handling of multiple source files, as well as the specific error encountered by the original poster.

happysauce
Messages
42
Reaction score
0
So I just started teaching myself C++ using visual studio 2010. I started with a nice easy program.

First thing I did was created a new project called "Tutorial." Under source files I right clicked and selected add -> new item, I named it Introduction.cpp. I created this:

#include <iostream>
using namespace std;

int main ()
{
count << "Hello World";
count << endl;
count << "My name is Neil";

system("pause");
return 0;
}



Worked out fine. It compiled and ran properly.

So I added another item and named it variables.cpp and made this:

#include <iostream>
using namespace std;

int main ()
{
int a, b, c;
int sum;


a=1;
b=2;
c=3;
a=a+4;
sum = a+b+c;


count << sum;
system("pause");
return 0;

}

This time when I compile and run I get an error Unable to start program "Tutorials/Debug/Tutorial.exe the system in the file cannot be found.

So I go back and try the other program and i get the same error. A lot of people online say to check the Debug file and look for it, but I didn't find any. I did find tutorial.exe.imbed.manifest though. I don't really know what's going on or how to fix this.
 
Technology news on Phys.org


Are you building a project with two main() functions? That should result in a linking error.
 


Ah that makes sense. I actually fixed it by just making another project with variables instead. So now I have a projected name introduction and a project named variables. My question now is, can I have two different codes in a project using no main function, like name one of them function_one () and the other function_two () (or even main)?
 


happysauce said:
My question now is, can I have two different codes in a project using no main function, like name one of them function_one () and the other function_two () (or even main)?

Your source must contain one main() function. This is the program's entry point. What you name other functions in the same source file or in different source files in the same project is up to you.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 6 ·
Replies
6
Views
12K
  • · Replies 22 ·
Replies
22
Views
4K
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 70 ·
3
Replies
70
Views
5K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 40 ·
2
Replies
40
Views
3K
Replies
3
Views
1K