Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7435591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:05:58+00:00 2026-05-29T10:05:58+00:00

I’m learning linear algebra, and thought I’d transform some of my new found knowledge

  • 0

I’m learning linear algebra, and thought I’d transform some of my new found knowledge into a small C++ program. For the numbers, I stumbled across CLN, a Class Library for Numbers, which I’m trying to use.

LinearEquation.h:

#include <iostream>
#include <cln/real.h>
#include <cln/rational.h>
using namespace std;
using namespace cln;

class LinearEquation{
public:
  // constructor
  LinearEquation(cl_R* coefficients, int numFactors, cl_R constant);

  // copy constructor
  LinearEquation(const LinearEquation& le);

  // assignment constructor
  LinearEquation& operator=(const LinearEquation& rhs);

  // destructor
  ~LinearEquation();

  /*
    isSolution returns true if a provided set of rational numbers is a solution
    to this linear Equation, and false otherwise.

    No error checking is done, thus s and num is expected to match the number 
    of items in _coefficients;
  */
  bool isSolution(const cl_R* s, int num);

private:
  int _numFactors;
  cl_R* _coefficients;
  cl_R _constant;
};

LinearEquation.cpp:

#include "LinearEquation.h"

// constructor
LinearEquation::LinearEquation(cl_R* coefficients,
                   int numFactors,
                   cl_R constant){
  _numFactors = numFactors;
  _coefficients = new cl_R[numFactors];
  for(int i=0; i<numFactors; i++){
    _coefficients[i] = coefficients[i];
  }
  _constant = constant;
}

// copy constructor
LinearEquation::LinearEquation(const LinearEquation& obj){
  _numFactors = obj._numFactors;
  _coefficients = new cl_R[_numFactors];
  for(int i=0; i<_numFactors; i++){
    _coefficients[i] = obj._coefficients[i];
  }
  _constant = obj._constant;
}

// assignment constructor
LinearEquation& LinearEquation::operator=(const LinearEquation& le){
  if(this != &le){
    _numFactors = le._numFactors;
    delete [] _coefficients;
    _coefficients = new cl_R[_numFactors];
    for(int i=0; i<_numFactors; i++){
      _coefficients[i] = le._coefficients[i];
    }
    _constant = le._constant;
  }
}

// destructor
LinearEquation::~LinearEquation(){
  delete [] _coefficients;
}

bool LinearEquation::isSolution(const cl_R* s, int num){
  cl_R sum = 0;
  for(int i=0; i<_numFactors; i++){
    sum = sum + (_coefficients[i] * s[i]);
  }
  return sum == _constant;
}

and finally, main.cpp

#include <cln/integer.h>
#include <cln/real.h>
#include "LinearEquation.h"
#include <iostream>
using namespace cln;
using namespace std;

int main(){
  int le1NumFactors = 2;
  cl_R* le1Coefficients = new cl_R[le1NumFactors];
  le1Coefficients[0] = 3;
  le1Coefficients[1] = 2;
  cl_R le1Constant = 7;
  LinearEquation le1(le1Coefficients, le1NumFactors, le1Constant);

  int le2NumFactors = 2;
  cl_R* le2Coefficients = new cl_R[le2NumFactors];
  le2Coefficients[0] = -1;
  le2Coefficients[1] = 1;
  cl_R le2Constant = 6;
  LinearEquation le2(le2Coefficients, le2NumFactors, le2Constant);

  cl_R* solution = new cl_R[le2NumFactors];
  solution[0] = -1;
  solution[1] = 5;

  cout << "(-1, 5) is " << (le1.isSolution(solution, 2) ? "" : "not ")
       << "a solution to le1." << endl;
  cout << "(-1, 5) is " << (le2.isSolution(solution, 2) ? "" : "not ")
       << "a solution to le2." << endl;

  delete [] le1Coefficients;
  delete [] le2Coefficients;
  delete [] solution;

  return 0;
}

g++ LinearEquation.h LinearEquation.cpp -c

works fine, but

g++ main.cpp LinearEquation.o

doesn’t. The following error message is produced:

lowerkey@cassiopeia:~/Desktop/math$ g++ main.cpp LinearEquation.o
/tmp/ccMceM9l.o: In function
__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x4ab): undefined reference to
cln::cl_random_def_init_helper::cl_random_def_init_helper()’
main.cpp:(.text+0x4b0): undefined reference to
cln::cl_random_def_init_helper::~cl_random_def_init_helper()'
main.cpp:(.text+0x4e0): undefined reference to
cln::cl_FF_globals_init_helper::cl_FF_globals_init_helper()’
main.cpp:(.text+0x4e5): undefined reference to
cln::cl_FF_globals_init_helper::~cl_FF_globals_init_helper()'
main.cpp:(.text+0x509): undefined reference to
cln::cl_DF_globals_init_helper::cl_DF_globals_init_helper()’
main.cpp:(.text+0x50e): undefined reference to
cln::cl_DF_globals_init_helper::~cl_DF_globals_init_helper()'
main.cpp:(.text+0x532): undefined reference to
cln::cl_LF_globals_init_helper::cl_LF_globals_init_helper()’
main.cpp:(.text+0x537): undefined reference to
cln::cl_LF_globals_init_helper::~cl_LF_globals_init_helper()'
/tmp/ccMceM9l.o: In function
cln::cl_gc_dec_pointer_refcount(cln::cl_heap*)’:
main.cpp:(.text._ZN3cln26cl_gc_dec_pointer_refcountEPNS_7cl_heapE[cln::cl_gc_dec_pointer_refcount(cln::cl_heap*)]+0x28):
undefined reference to cln::cl_free_heap_object(cln::cl_heap*)'
/tmp/ccMceM9l.o: In function
cln::cl_I_classes_dummy::cl_I_classes_dummy()’:
main.cpp:(.text._ZN3cln18cl_I_classes_dummyC1Ev[cln::cl_I_classes_dummy::cl_I_classes_dummy()]+0x9):
undefined reference to cln::cl_class_fixnum' LinearEquation.o: In
function
LinearEquation::isSolution(cln::cl_R const*, int)’:
LinearEquation.cpp:(.text+0x61a): undefined reference to
cln::operator*(cln::cl_R const&, cln::cl_R const&)'
LinearEquation.cpp:(.text+0x636): undefined reference to
cln::operator+(cln::cl_R const&, cln::cl_R const&)’ LinearEquation.o:
In function __static_initialization_and_destruction_0(int, int)':
LinearEquation.cpp:(.text+0x741): undefined reference to
cln::cl_random_def_init_helper::cl_random_def_init_helper()’
LinearEquation.cpp:(.text+0x746): undefined reference to
cln::cl_random_def_init_helper::~cl_random_def_init_helper()'
LinearEquation.cpp:(.text+0x76a): undefined reference to
cln::cl_FF_globals_init_helper::cl_FF_globals_init_helper()’
LinearEquation.cpp:(.text+0x76f): undefined reference to
cln::cl_FF_globals_init_helper::~cl_FF_globals_init_helper()'
LinearEquation.cpp:(.text+0x793): undefined reference to
cln::cl_DF_globals_init_helper::cl_DF_globals_init_helper()’
LinearEquation.cpp:(.text+0x798): undefined reference to
cln::cl_DF_globals_init_helper::~cl_DF_globals_init_helper()'
LinearEquation.cpp:(.text+0x7bc): undefined reference to
cln::cl_LF_globals_init_helper::cl_LF_globals_init_helper()’
LinearEquation.cpp:(.text+0x7c1): undefined reference to
cln::cl_LF_globals_init_helper::~cl_LF_globals_init_helper()'
LinearEquation.o: In function
cln::operator==(cln::cl_R const&,
cln::cl_R const&)’:
LinearEquation.cpp:(.text._ZN3clneqERKNS_4cl_RES2_[cln::operator==(cln::cl_R
const&, cln::cl_R const&)]+0x14): undefined reference to
`cln::equal(cln::cl_R const&, cln::cl_R const&)’ collect2: ld returned
1 exit status

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:05:59+00:00Added an answer on May 29, 2026 at 10:05 am

    Looks like you aren’t linking the cln library. Try the following (assuming the library is installed correctly):

    g++ main.cpp LinearEquation.o -lcln
    

    See the documentation for more details on compiling:
    http://www.ginac.de/CLN/cln_11.html#SEC64

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.