D.exe not found

I created an empty project called "D" for c++. I just do the basic hello world program and it works just fine. The problem comes when I try to build the same hello world code where I create an object. The class is in a header file (.h). when I try to build the simple code I ran into a pop up that says "Unable to start program '(address where my project is located)\D.exe'. The system cannot find the file specified ." I'm using VS community 2019 for the first time.

**main.cpp**

i
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include "fraction.h"

using namespace std;

nt main()
{
	Fraction m1;
	cout << "Hello World";
}

**fraction.h**

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <fstream>
#ifndef FRACTION_H
#define FRACTION_H

class Fraction
{
private:
    int num;
    int den;
public:
    Fraction();
    void setNum(int);
    void setDen(int);
    int getNum();
    int getDen();
    int gcd(int, int);
    void simplify();
    void add(int, int);
    void multiply(int, int);
    void print();

};

#endif // FRACTION_H 
Last edited on
Are you getting an actual compiler error besides that message?
What is the output when you simply build the project, but don't run it?

In your actual file system, do you see any file called D.exe? (e.g. inside a Debug or bin folder, perhaps)
There is no compiler error although I get a fatal error message in the console which is the following in the 4th line.

1>------ Build started: Project: D, Configuration: Debug Win32 ------
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall Fraction::Fraction(void)" (??0Fraction@@QAE@XZ) referenced in function _main
1>C:\Users\joshu\Documents\Tec\New folder\D\Debug\D.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "D.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I get no match when I run a search for D.exe in the project's file.

Its trying to initialize all your variables and creating the object Fraction but you got no Fraction.cpp file to implement the fraction constructor.

create a fraction.cpp class and implement what the functions should do
fraction.cpp
1
2
3
4
5
6
#include fraction.h

Fraction::Fraction()
{
    do stuff
}


then include it in main.cpp and see if that fixes it
then include it in main.cpp and see if that fixes it

NO!!!!

Never include one .cpp file in another!!!

Your IDE will compile both .cpp files and link the resultant objects together to make the final executable.
you need to add both .cpp files and both .h files to your project.

visual studio likes to put the resulting exe in a sub-folder, so look in /debug and /release (depending on how you compiled) for your .exe file. case in point:
C:\Users\joshu\Documents\Tec\New folder\D\Debug

when it fails to compile, it does not make the .exe file.
Build: 0 succeeded, 1 failed

if it compiles correctly, it will say 1 succeeded, 0 failed instead, or something like that.
Last edited on
Thx guys
Topic archived. No new replies allowed.