0

Calculator.h

#ifndef CALCULATOR_H
#define CALCULATOR_H

class Calculator
{
public:
    void run();
};

#endif

Calculator.cpp

#include <iostream>
using namespace std;

#include "Calculator.h"
#include "Adder.h"

void Calculator::run(){
    cout << "두 개의 수를 입력하세요>>";
    int a, b;
    cin >> a >> b;
    Adder adder(a,b);
    cout << adder.process();
}

Adder.h

#ifndef ADDER_H
#define ADDER_H

class Adder
{
    int op1, op2;

public:
    Adder(int a, int b);
    int process();
};

#endif

Adder.cpp

#include "Adder.h"
Adder::Adder(int a, int b)
{
    op1 = a;
    op2 = b;
}

int Adder::process()
{
    return op1 + op2;
}

main.cpp

#include "Calculator.h"

int main(){
    Calculator calc;
    calc.run(); 
    return 0;
} 

Error

Executing task in folder Basic: /usr/bin/g++ -std=c++11 -g /Users/youblue/Documents/Basic/C++/HelloWorld/cpp_programming_class/week_3/main.cpp -o /Users/youblue/Documents/Basic/C++/HelloWorld/cpp_programming_class/week_3/main.out < Undefined symbols for architecture arm64: "Calculator::run()", referenced from: _main in main-a40f82.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) The terminal process "zsh '-c', '/usr/bin/g++ -std=c++11 -g /Users/youblue/Documents/Basic/C++/HelloWorld/cpp_programming_class/week_3/main.cpp -o /Users/youblue/Documents/Basic/C++/HelloWorld/cpp_programming_class/week_3/main.out'" failed to launch (exit code: 1). My laptop is M1 MBP.

I can't compile main.cpp in vscode.

Chung
  • 13
  • 3
  • 1
    If you don't set up configuration scripts or forget to list all source files in it, then only a single source file will be built and linked into the application. You need to configure VSCode to invoke the compiler and linker with *all* files in your project. Since you're on a macOS system [this guide about using Clang together with VSCode](https://code.visualstudio.com/docs/cpp/config-clang-mac) should be very helpful. – Some programmer dude Sep 23 '21 at 03:54

0 Answers0