Question:
C++ NEED HELP ASAP [Linker error] undefined reference to `openFile?
CHRISTY
2011-12-12 18:59:25 UTC
I am stuck and need help

I am working on a menu and am stuck with a linker error and cannot get any farther

I just need the menu and header files the .exe parts i have completed. teacher didn't go over header's, classes, and structures. the assignment is to create a menu driven program inside a function with switch with only two directives to call the function

menu has 5 options to open the following programs: Inventory.exe, orders.exe, shipping.exe, returns.exe, and the last to close the program with yes or no classes must be in external headers and included in project (yes i know the program file names are different in what I am pasting.
include one additional function in a separate header file the menu should open the .exe file allow you close it or run again and to return to the menu and choose another option. to exit the menu after choosing 5 it will ask for a confirmation.
be sure and validate your input
I welcome any further input on this being correct as i cannot see what is wrong because of the error and have a deadline due in an hour.
I will pastebin the external files

#include
#include
#include
#include
#include

using namespace std;

int menu()
{
int option;

cout << "Final Exam Program\n";
cout << "----------------------------\n";
cout << "1) Math Tutor\n";
cout << "2) File Processing\n";
cout << "3) Driver's License\n";
cout << "4) Inventory Class\n";
cout << "5) Exit\n\n";
cout << "Enter 1, 2, 3, 4, or 5: ";
cin >> option;

while (option < 1 || option > 6)
{
cout << "Invalid Selection\n";
cin >> option;
}
return option;
}

// Function prototypes
void openFile(fstream &);
int menu();
void file(fstream &);


int main()
{
int option;
fstream file;



openFile(file);
do
{
option = menu();
switch(option)
{
case 1 : fstream ("mathtutor.exe"); return 0;
break;
case 2 : fstream ("fileprocessing.exe"); return 0;
break;
case 3 : fstream ("driverslicense.exe"); return 0;
break;
case 4 : fstream ("inventoryclass.exe"); return 0;
break;
case 6 : cout << "Exiting program.\n\n";
}

} while (option != 5);
file.close();
return (0);
}
Four answers:
Ratchetr
2011-12-12 19:08:14 UTC
If you search your code for openFile, you find it in 2 places:



void openFile(fstream &);

...

openFile(file);



The first is a function prototype. It tells the compiler that there will be a function named openFile that takes a reference to an fstream defined somewhere later on.



The second is a call to that function.



What is missing is the actual function. Where is the openFile function in your code? openFile isn't something that comes with C++. All it is right now is a promise you made to the compiler that *you* would supply such a function. You broke that promise. That is what the compiler is complaining about. You need to write the openFile function.
?
2011-12-12 19:08:34 UTC
What are you using for a compiler? The software may not have the dll containing fstream functions as default in the libraries used. It's been quite a while since I've done any C++, but check and see what library fstream is in and see if it is being used. If it's not you will have to add it to the list of dll's being used for this project. I wish I could do more to help but like I said, it's been quite a while and I can't remember where the options are to check. Use the handy help system and see if that will tell you about .dll's and how to use them for your project.



Edit:

Ratchetr brings up a good point, is openFile a function that is already available to you or is it one you are supposed to write?



Edit again:

I need to be paying more attention. He's right. You have a function prototype but no function. You have to actually write a function, it doesn't exist simply because you made a prototype. Also, it's standard to put your prototype's at the top of the file. I know you don't have to in C++ like you do in C, but it is how it's usually done and it is much more readable than plopping it in where you did. Just some advice. My prof was very picky about structure in our code. Also, you don't need a prototype for the main function. That's a given that your program has that.
mcswain
2016-11-13 01:46:54 UTC
see first you may desire to be responsive to what's a linker and what's a linker blunders. After code compilation, that code is proper with each and every of the library purposes existent on your turboC itemizing...Now, it quite is the job of the linker to be sure the physique of the purposes u have used like printf, scanf etc...Now you have used one function observed as "symbol_circle" which you have declared and observed as from the substantial function yet you havent declared the physique of it...throughout the time of linking time, the linker sees that the function is observed as yet it has have been given no corresponding code to execute...write a physique of that function.....then u will locate no linker blunders will take place..
2011-12-12 19:50:20 UTC
after you figure out whether you need openFile() function

you'll run into more problems. fstream creates an instance of fstream but you need to assign into your fstream declared "file" variable. fstream is used for reading and writing to files not executing executable files(.exe)



to execute a program you could use

#include "process.h"



_execl("C:\\Windows\\System32\\calc.exe","C:\\Windows\\System32\\calc.exe");


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...