Question: I keep getting an error Undefined symbols for architecturex86_64 & ld: symbol(s) not found for architecture x86_64 I'm running a simple addition program, I have

I keep getting an error "Undefined symbols for architecturex86_64" & "ld: symbol(s) not found for architecture x86_64"

I'm running a simple addition program, I have 3 files: "add.h","add.cpp", "main.cpp"

This is my header file:

___________________

#pragma once

#include

int add(int x, int y);

___________________

Then my add.cpp file:

___________________

#include

using namespace std;

#include "add.h"

int add(int x, int y)

{

return x + y;

}

int main()

{

return 0;

}

___________________

And my main.cpp file:

___________________

#include

using namespace std;

#include "add.h"

int main()

{

cout << "3 + 4 =" << add(3,4) << endl;

return 0;

}

___________________

I can build my add.cpp successfully but my main.cpp filegives me the following error:

Undefined symbols for architecture x86_64:
"add(int, int)", referenced from:
_main in main-deee09.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to seeinvocation)

Build finished with error(s).

x-------x

I'm running it on Visual Studio on a mac, I did some researchand know that there is something wrong with my IDE, I just have noidea how to fix it.

Thank you!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!