Author Topic: compiling error  (Read 2849 times)

Offline cpp_fanatic

  • Single posting newcomer
  • *
  • Posts: 1
compiling error
« on: September 18, 2023, 06:37:02 am »
I'm writing a lesson code from a C++ for dummies book and ran into this error.

Code
/*
        CallMemberFunction - define and invoke a function
                             that a member of the class Student

*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

class Student
{

 public:
     // add a completed course to the record
     double addCourse(int hours, double grade)
     {
       // calculate the sum of all courses times
       // the average grade
       double weightedGPA;
       weightedGPA = semesterHours * gpa;

       // now add in the new course
       semesterHours += hours;
       weightedGPA += grade * hours;
       gpa = weightedGPA / semesterHours;
       // return the new gpa
       return gpa;
     }
  int semesterHours;
  double gpa;
};

int main(int nNumberofArgs, char* pszArgs[])
{
    // create a Student object and initialize it
    Student s;
    s.semesterHours = 3;
    s.gpa = 3.0;

    // the values before the call

    cout << "Before: s = (" << s.semesterHours
         << ", " << s.gpa << ")" << endl;
    // the following subjects the data members of the s
    // object to the member function addCourse()
    cout << "Adding 3 hours with a grade of 4.0" << endl;
    s.addCourse(3, 4.0); // call the member function

    // the values are now changed
    cout << "After: s = (" << s.semesterHours
         << ", " << s.gpa << ")" << endl;

    // wait until user is ready before terminating program
    // to allow the user to see program results
    cout << "Press Enter to continue...." << endl;
    cin.ignore(10,'\n');
    cin.get();
    return 0;
}

Code
||=== Build: Debug in CallMemberFunction (compiler: GNU GCC Compiler) ===|
||error: ld returned 1 exit status|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

I started this on a windows 11 home laptop and then tried to compile it on a windows 11 pro computer and ran into this problem. I added these two compiler flags to the IDE -static-libgcc -static-libstdc++ and still getting this error, any help greatly appreciated.

MichaelAgarkov

  • Guest
Re: compiling error
« Reply #1 on: September 18, 2023, 11:40:10 am »
Code
error: ld returned 1 exit status
is usually fixed by reinstalling the compiler. Here's others who got the same error.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1487
Re: compiling error
« Reply #2 on: September 18, 2023, 12:52:46 pm »
Post a full rebuild log, read this carefully for instructions.

EDIT: You are using the wrong forum, this is for C::B development only. Next time select another, for example Help.
« Last Edit: September 18, 2023, 01:06:39 pm by Miguel Gimenez »