0
class Admin {
public:
    string contact;
    bool add_course(Running_Courses &rc_list);
    bool delete_course(Running_Courses &rc_list);
    bool add_student(Students_list &s_list);
    bool delete_student(Students_list &s_list,Running_Courses &rc_list);
    bool add_student_to_course(Course &c_obj, Student s_obj);
    bool delete_student_from_course(Course &c_obj, Student s_obj);
};

This is class Admin definition in Admin.h It's methods implementations in Admin.cpp are(I'll post only for one function)-

bool Admin::add_course(Running_Courses &rc_list)  {
    string code;
    
    cout<<"Enter course code: \n";
    cin>>code;
    
    Course temp(code);
    rc_list.course_list.push_back(temp);

return true;
}

main.cpp contains

#include "Admin.h"

int main()  {

    Admin a1;
    Running_Courses r;
    a1.add_course(r);

}

When I compile main.cpp using the command

clang++ -std=c++20 main.cpp

I get the error

Undefined symbols for architecture arm64:
  "Admin::add_course(Running_Courses&)", referenced from:
      _main in main-c64d1c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I don't understand what's wrong. (I hope the code posted is sufficient)

  • 3
    Your linker error is caused by this: `clang++ -std=c++20 main.cpp` You did not build `Admin.cpp` into your executable. Your compiler will only build the files that you list. – drescherjm Apr 17 '22 at 14:15
  • BTW, if you are using VSCode in it's default configuration remember that the default behavior of this IDE is to build only the active file. The documentation explains how to modify your `tasks.json` to have it build all files in your folder. I have a recent answer that explains this further: [https://stackoverflow.com/questions/70856563/vscode-g-it-isnt-finding-cpp-definition-files/70856902#70856902](https://stackoverflow.com/questions/70856563/vscode-g-it-isnt-finding-cpp-definition-files/70856902#70856902) – drescherjm Apr 17 '22 at 14:41
  • @drescherjm Thanks for pointing out build of active file. I checked your recent answer and updated tasks.json as advised. However, the problem still persists.I added another void function in class Admin definition that simply prints out "Hello". I commented out add_course(r) and called this newly added function instead, and the program worked well(printed "Hello"). So, I guess it has something to with the function(and the rest that follow it). – Vedant Bhandare Apr 17 '22 at 15:59
  • If you have code-runner enabled remove it. Also make sure that the tasks.json you are using is enabled. – drescherjm Apr 17 '22 at 16:00
  • ***So, I guess it has something to with the function(and the rest that follow it)*** Your command line showed you were only building main.cpp. It needs to be `clang++ -std=c++20 main.cpp Admin.cpp` also if there was a problem in building `Admin.cpp` your compiler should have told you that there were errors in that file. – drescherjm Apr 17 '22 at 16:01
  • It works now. I used the command clang++ -std=c++20 main.cpp Admin.cpp – Vedant Bhandare Apr 19 '22 at 02:49

0 Answers0