Apple Mach O-Linker Error Xcode (C++): Undefined symbols for architecture x86_64
Why am I getting the following error with Xcode?
Undefined symbols for architecture x86_64:
"displayFile()", referenced from:
_main in main.o
"quitProgram(bool&)", referenced from:
_main in main.o
"editFile()", referenced from:
_main in main.o
"openFile()", referenced from:
_main in main.o
"saveFile()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
Here is the number_enforcer.hpp:
#ifndef number_enforcer_hpp
#define number_enforcer_hpp
class Enforcer {
private:
int int_n;
double n;
public:
int natural_number_enforcer(int min, int max);
};
#endif /* number_enforcer_hpp */
The number_enforcer.cpp:
#include "number_enforcer.hpp"
#include <iostream>
using namespace std;
//***********************************************************************
// Definition of function natural_number_enforcer *
// *
// forces input for a variable to be a natural number. *
// WARNING: Does not work for numbers too large for type int (32 bits) *
//***********************************************************************
int Enforcer::natural_number_enforcer(int min, int max)
{
do
{
if (cin >> n) // input n and see if input is a number
{ // If n is a number, then:
cin.ignore(1000000000000000000, 'n'); // if first characters form a number,...
// ...this ignores any extra junk typed after that number.
int_n = n; // assigns input of type double to int_n of type int
// int_n is the truncated version of n (if n is a decimal not too large for type int)
if (n != int_n || n < min || n > max) // Test if n is a natural number (it should equal the truncated version int_n and be greater than 1).
{ // Otherwise, n is not a natural number (or else n is too large for type int).
cout << "nError: Input needs to be a whole number between " << min << " and " << max << "." << endl;
}
else // if inputed n is actually a natural number, then:
{
break; // quit the do-while loop and keep the acceptable input for n
}
}
else // If n is not a number, then:
{
cout << "nA letter/punctuation is not a number.n"; // tell the user that their input was not a number
cin.clear(); // clear the input (or else the program will go crazy and repeat a part forever)
cin.ignore(1000000000000000000, 'n'); // ignore potential extra inputed junk as well
}
cout << "Enter a new number:t"; // tell the user to input a natural number
} while (true); // loop until user inputs a natural number
return n;
}
And the main.cpp:
#include <iostream>
#include <fstream>
#include <string>
#include "number_enforcer.hpp"
using namespace std;
Enforcer enf; //calls to class Enforcer for managing input
//=======FUNCTIONS=======
void createFile(int (&x)[100]);
void saveFile();
void openFile();
void displayFile();
void editFile();
void quitProgram(bool &);
//=======================
int main() {
int menuOption; //user-defined choice for Main Menu
bool quit; //true --> quit program
int scores[100]; //declare array for storing scores with a limit of 100 items
do {
//=======MAIN MENU=======
cout << "What would you like to do?n" <<
"1. Create New Filen" <<
"2. Save Current Informationn" <<
"3. Open Another Filen" <<
"4. Display Current Scoresn" <<
"5. Modify Certain Scoresn" <<
"6. Quit" << endl;
menuOption = enf.natural_number_enforcer(1, 6);
switch (menuOption) {
case 1:
createFile(scores);
break;
case 2:
saveFile();
break;
case 3:
openFile();
break;
case 4:
displayFile();
break;
case 5:
editFile();
break;
case 6:
quitProgram(quit);
break;
default:
break;
}
} while (!quit);
return 0;
}
void createFile(int (&x)[100]) {
int subMenuOption; //user-defined choice for Sub Menu
int numberOfScores; //user-defined amount of scores to store
cout << "Are you sure you want to create a new file?n" <<
"(This will overwrite any unsaved progress)nn" <<
"1. Yesn" <<
"2. No" << endl;
subMenuOption = enf.natural_number_enforcer(1, 2);
if (subMenuOption == 1) {
cout << "How many scores do you wish to enter (up to 100)?: t";
numberOfScores = enf.natural_number_enforcer(1, 100);
for (int i = 0; i < numberOfScores - 1; i++) {
cout << "Enter Score #" << i + 1 << ": t";
x[i] = enf.natural_number_enforcer(0, 100000);
}
for (int i = 0; i < numberOfScores - 1; i++) {
cout << x[i] << endl;
}
}
}
I just started my project before noticing this strange error. How to fix it?
I assume it has to do with my header files that I added, but I remember testing it before and it working. The only thing I added after that was the prototypes and the createFile() function, then suddenly it wouldn't build. I tried removing the createFile() function but to no avail.
c++ macos xcode9
add a comment |
Why am I getting the following error with Xcode?
Undefined symbols for architecture x86_64:
"displayFile()", referenced from:
_main in main.o
"quitProgram(bool&)", referenced from:
_main in main.o
"editFile()", referenced from:
_main in main.o
"openFile()", referenced from:
_main in main.o
"saveFile()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
Here is the number_enforcer.hpp:
#ifndef number_enforcer_hpp
#define number_enforcer_hpp
class Enforcer {
private:
int int_n;
double n;
public:
int natural_number_enforcer(int min, int max);
};
#endif /* number_enforcer_hpp */
The number_enforcer.cpp:
#include "number_enforcer.hpp"
#include <iostream>
using namespace std;
//***********************************************************************
// Definition of function natural_number_enforcer *
// *
// forces input for a variable to be a natural number. *
// WARNING: Does not work for numbers too large for type int (32 bits) *
//***********************************************************************
int Enforcer::natural_number_enforcer(int min, int max)
{
do
{
if (cin >> n) // input n and see if input is a number
{ // If n is a number, then:
cin.ignore(1000000000000000000, 'n'); // if first characters form a number,...
// ...this ignores any extra junk typed after that number.
int_n = n; // assigns input of type double to int_n of type int
// int_n is the truncated version of n (if n is a decimal not too large for type int)
if (n != int_n || n < min || n > max) // Test if n is a natural number (it should equal the truncated version int_n and be greater than 1).
{ // Otherwise, n is not a natural number (or else n is too large for type int).
cout << "nError: Input needs to be a whole number between " << min << " and " << max << "." << endl;
}
else // if inputed n is actually a natural number, then:
{
break; // quit the do-while loop and keep the acceptable input for n
}
}
else // If n is not a number, then:
{
cout << "nA letter/punctuation is not a number.n"; // tell the user that their input was not a number
cin.clear(); // clear the input (or else the program will go crazy and repeat a part forever)
cin.ignore(1000000000000000000, 'n'); // ignore potential extra inputed junk as well
}
cout << "Enter a new number:t"; // tell the user to input a natural number
} while (true); // loop until user inputs a natural number
return n;
}
And the main.cpp:
#include <iostream>
#include <fstream>
#include <string>
#include "number_enforcer.hpp"
using namespace std;
Enforcer enf; //calls to class Enforcer for managing input
//=======FUNCTIONS=======
void createFile(int (&x)[100]);
void saveFile();
void openFile();
void displayFile();
void editFile();
void quitProgram(bool &);
//=======================
int main() {
int menuOption; //user-defined choice for Main Menu
bool quit; //true --> quit program
int scores[100]; //declare array for storing scores with a limit of 100 items
do {
//=======MAIN MENU=======
cout << "What would you like to do?n" <<
"1. Create New Filen" <<
"2. Save Current Informationn" <<
"3. Open Another Filen" <<
"4. Display Current Scoresn" <<
"5. Modify Certain Scoresn" <<
"6. Quit" << endl;
menuOption = enf.natural_number_enforcer(1, 6);
switch (menuOption) {
case 1:
createFile(scores);
break;
case 2:
saveFile();
break;
case 3:
openFile();
break;
case 4:
displayFile();
break;
case 5:
editFile();
break;
case 6:
quitProgram(quit);
break;
default:
break;
}
} while (!quit);
return 0;
}
void createFile(int (&x)[100]) {
int subMenuOption; //user-defined choice for Sub Menu
int numberOfScores; //user-defined amount of scores to store
cout << "Are you sure you want to create a new file?n" <<
"(This will overwrite any unsaved progress)nn" <<
"1. Yesn" <<
"2. No" << endl;
subMenuOption = enf.natural_number_enforcer(1, 2);
if (subMenuOption == 1) {
cout << "How many scores do you wish to enter (up to 100)?: t";
numberOfScores = enf.natural_number_enforcer(1, 100);
for (int i = 0; i < numberOfScores - 1; i++) {
cout << "Enter Score #" << i + 1 << ": t";
x[i] = enf.natural_number_enforcer(0, 100000);
}
for (int i = 0; i < numberOfScores - 1; i++) {
cout << x[i] << endl;
}
}
}
I just started my project before noticing this strange error. How to fix it?
I assume it has to do with my header files that I added, but I remember testing it before and it working. The only thing I added after that was the prototypes and the createFile() function, then suddenly it wouldn't build. I tried removing the createFile() function but to no avail.
c++ macos xcode9
add a comment |
Why am I getting the following error with Xcode?
Undefined symbols for architecture x86_64:
"displayFile()", referenced from:
_main in main.o
"quitProgram(bool&)", referenced from:
_main in main.o
"editFile()", referenced from:
_main in main.o
"openFile()", referenced from:
_main in main.o
"saveFile()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
Here is the number_enforcer.hpp:
#ifndef number_enforcer_hpp
#define number_enforcer_hpp
class Enforcer {
private:
int int_n;
double n;
public:
int natural_number_enforcer(int min, int max);
};
#endif /* number_enforcer_hpp */
The number_enforcer.cpp:
#include "number_enforcer.hpp"
#include <iostream>
using namespace std;
//***********************************************************************
// Definition of function natural_number_enforcer *
// *
// forces input for a variable to be a natural number. *
// WARNING: Does not work for numbers too large for type int (32 bits) *
//***********************************************************************
int Enforcer::natural_number_enforcer(int min, int max)
{
do
{
if (cin >> n) // input n and see if input is a number
{ // If n is a number, then:
cin.ignore(1000000000000000000, 'n'); // if first characters form a number,...
// ...this ignores any extra junk typed after that number.
int_n = n; // assigns input of type double to int_n of type int
// int_n is the truncated version of n (if n is a decimal not too large for type int)
if (n != int_n || n < min || n > max) // Test if n is a natural number (it should equal the truncated version int_n and be greater than 1).
{ // Otherwise, n is not a natural number (or else n is too large for type int).
cout << "nError: Input needs to be a whole number between " << min << " and " << max << "." << endl;
}
else // if inputed n is actually a natural number, then:
{
break; // quit the do-while loop and keep the acceptable input for n
}
}
else // If n is not a number, then:
{
cout << "nA letter/punctuation is not a number.n"; // tell the user that their input was not a number
cin.clear(); // clear the input (or else the program will go crazy and repeat a part forever)
cin.ignore(1000000000000000000, 'n'); // ignore potential extra inputed junk as well
}
cout << "Enter a new number:t"; // tell the user to input a natural number
} while (true); // loop until user inputs a natural number
return n;
}
And the main.cpp:
#include <iostream>
#include <fstream>
#include <string>
#include "number_enforcer.hpp"
using namespace std;
Enforcer enf; //calls to class Enforcer for managing input
//=======FUNCTIONS=======
void createFile(int (&x)[100]);
void saveFile();
void openFile();
void displayFile();
void editFile();
void quitProgram(bool &);
//=======================
int main() {
int menuOption; //user-defined choice for Main Menu
bool quit; //true --> quit program
int scores[100]; //declare array for storing scores with a limit of 100 items
do {
//=======MAIN MENU=======
cout << "What would you like to do?n" <<
"1. Create New Filen" <<
"2. Save Current Informationn" <<
"3. Open Another Filen" <<
"4. Display Current Scoresn" <<
"5. Modify Certain Scoresn" <<
"6. Quit" << endl;
menuOption = enf.natural_number_enforcer(1, 6);
switch (menuOption) {
case 1:
createFile(scores);
break;
case 2:
saveFile();
break;
case 3:
openFile();
break;
case 4:
displayFile();
break;
case 5:
editFile();
break;
case 6:
quitProgram(quit);
break;
default:
break;
}
} while (!quit);
return 0;
}
void createFile(int (&x)[100]) {
int subMenuOption; //user-defined choice for Sub Menu
int numberOfScores; //user-defined amount of scores to store
cout << "Are you sure you want to create a new file?n" <<
"(This will overwrite any unsaved progress)nn" <<
"1. Yesn" <<
"2. No" << endl;
subMenuOption = enf.natural_number_enforcer(1, 2);
if (subMenuOption == 1) {
cout << "How many scores do you wish to enter (up to 100)?: t";
numberOfScores = enf.natural_number_enforcer(1, 100);
for (int i = 0; i < numberOfScores - 1; i++) {
cout << "Enter Score #" << i + 1 << ": t";
x[i] = enf.natural_number_enforcer(0, 100000);
}
for (int i = 0; i < numberOfScores - 1; i++) {
cout << x[i] << endl;
}
}
}
I just started my project before noticing this strange error. How to fix it?
I assume it has to do with my header files that I added, but I remember testing it before and it working. The only thing I added after that was the prototypes and the createFile() function, then suddenly it wouldn't build. I tried removing the createFile() function but to no avail.
c++ macos xcode9
Why am I getting the following error with Xcode?
Undefined symbols for architecture x86_64:
"displayFile()", referenced from:
_main in main.o
"quitProgram(bool&)", referenced from:
_main in main.o
"editFile()", referenced from:
_main in main.o
"openFile()", referenced from:
_main in main.o
"saveFile()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
Here is the number_enforcer.hpp:
#ifndef number_enforcer_hpp
#define number_enforcer_hpp
class Enforcer {
private:
int int_n;
double n;
public:
int natural_number_enforcer(int min, int max);
};
#endif /* number_enforcer_hpp */
The number_enforcer.cpp:
#include "number_enforcer.hpp"
#include <iostream>
using namespace std;
//***********************************************************************
// Definition of function natural_number_enforcer *
// *
// forces input for a variable to be a natural number. *
// WARNING: Does not work for numbers too large for type int (32 bits) *
//***********************************************************************
int Enforcer::natural_number_enforcer(int min, int max)
{
do
{
if (cin >> n) // input n and see if input is a number
{ // If n is a number, then:
cin.ignore(1000000000000000000, 'n'); // if first characters form a number,...
// ...this ignores any extra junk typed after that number.
int_n = n; // assigns input of type double to int_n of type int
// int_n is the truncated version of n (if n is a decimal not too large for type int)
if (n != int_n || n < min || n > max) // Test if n is a natural number (it should equal the truncated version int_n and be greater than 1).
{ // Otherwise, n is not a natural number (or else n is too large for type int).
cout << "nError: Input needs to be a whole number between " << min << " and " << max << "." << endl;
}
else // if inputed n is actually a natural number, then:
{
break; // quit the do-while loop and keep the acceptable input for n
}
}
else // If n is not a number, then:
{
cout << "nA letter/punctuation is not a number.n"; // tell the user that their input was not a number
cin.clear(); // clear the input (or else the program will go crazy and repeat a part forever)
cin.ignore(1000000000000000000, 'n'); // ignore potential extra inputed junk as well
}
cout << "Enter a new number:t"; // tell the user to input a natural number
} while (true); // loop until user inputs a natural number
return n;
}
And the main.cpp:
#include <iostream>
#include <fstream>
#include <string>
#include "number_enforcer.hpp"
using namespace std;
Enforcer enf; //calls to class Enforcer for managing input
//=======FUNCTIONS=======
void createFile(int (&x)[100]);
void saveFile();
void openFile();
void displayFile();
void editFile();
void quitProgram(bool &);
//=======================
int main() {
int menuOption; //user-defined choice for Main Menu
bool quit; //true --> quit program
int scores[100]; //declare array for storing scores with a limit of 100 items
do {
//=======MAIN MENU=======
cout << "What would you like to do?n" <<
"1. Create New Filen" <<
"2. Save Current Informationn" <<
"3. Open Another Filen" <<
"4. Display Current Scoresn" <<
"5. Modify Certain Scoresn" <<
"6. Quit" << endl;
menuOption = enf.natural_number_enforcer(1, 6);
switch (menuOption) {
case 1:
createFile(scores);
break;
case 2:
saveFile();
break;
case 3:
openFile();
break;
case 4:
displayFile();
break;
case 5:
editFile();
break;
case 6:
quitProgram(quit);
break;
default:
break;
}
} while (!quit);
return 0;
}
void createFile(int (&x)[100]) {
int subMenuOption; //user-defined choice for Sub Menu
int numberOfScores; //user-defined amount of scores to store
cout << "Are you sure you want to create a new file?n" <<
"(This will overwrite any unsaved progress)nn" <<
"1. Yesn" <<
"2. No" << endl;
subMenuOption = enf.natural_number_enforcer(1, 2);
if (subMenuOption == 1) {
cout << "How many scores do you wish to enter (up to 100)?: t";
numberOfScores = enf.natural_number_enforcer(1, 100);
for (int i = 0; i < numberOfScores - 1; i++) {
cout << "Enter Score #" << i + 1 << ": t";
x[i] = enf.natural_number_enforcer(0, 100000);
}
for (int i = 0; i < numberOfScores - 1; i++) {
cout << x[i] << endl;
}
}
}
I just started my project before noticing this strange error. How to fix it?
I assume it has to do with my header files that I added, but I remember testing it before and it working. The only thing I added after that was the prototypes and the createFile() function, then suddenly it wouldn't build. I tried removing the createFile() function but to no avail.
c++ macos xcode9
c++ macos xcode9
edited Dec 29 '18 at 6:30
Cœur
17.6k9105145
17.6k9105145
asked Nov 28 '17 at 10:28
gvsvgvsv
82
82
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You declared but not defined these functions:
void saveFile();
void openFile();
void displayFile();
void editFile();
void quitProgram(bool &);
You call the functions in your code, so linker tries to find their implementation and fails.
Just add definitions for the functions as you did for createFile
.
That was it. Can't believe the solution was so simple
– gvsv
Nov 28 '17 at 19:06
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47529229%2fapple-mach-o-linker-error-xcode-c-undefined-symbols-for-architecture-x86-64%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You declared but not defined these functions:
void saveFile();
void openFile();
void displayFile();
void editFile();
void quitProgram(bool &);
You call the functions in your code, so linker tries to find their implementation and fails.
Just add definitions for the functions as you did for createFile
.
That was it. Can't believe the solution was so simple
– gvsv
Nov 28 '17 at 19:06
add a comment |
You declared but not defined these functions:
void saveFile();
void openFile();
void displayFile();
void editFile();
void quitProgram(bool &);
You call the functions in your code, so linker tries to find their implementation and fails.
Just add definitions for the functions as you did for createFile
.
That was it. Can't believe the solution was so simple
– gvsv
Nov 28 '17 at 19:06
add a comment |
You declared but not defined these functions:
void saveFile();
void openFile();
void displayFile();
void editFile();
void quitProgram(bool &);
You call the functions in your code, so linker tries to find their implementation and fails.
Just add definitions for the functions as you did for createFile
.
You declared but not defined these functions:
void saveFile();
void openFile();
void displayFile();
void editFile();
void quitProgram(bool &);
You call the functions in your code, so linker tries to find their implementation and fails.
Just add definitions for the functions as you did for createFile
.
answered Nov 28 '17 at 10:32
Anton MalyshevAnton Malyshev
6,42221838
6,42221838
That was it. Can't believe the solution was so simple
– gvsv
Nov 28 '17 at 19:06
add a comment |
That was it. Can't believe the solution was so simple
– gvsv
Nov 28 '17 at 19:06
That was it. Can't believe the solution was so simple
– gvsv
Nov 28 '17 at 19:06
That was it. Can't believe the solution was so simple
– gvsv
Nov 28 '17 at 19:06
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47529229%2fapple-mach-o-linker-error-xcode-c-undefined-symbols-for-architecture-x86-64%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown