How to link to GMP using C++ in Visual Studio Code's Code Runner (in Linux)?

I've been using Visual Studio Code Runner to compile C++ projects without a problem, but now I need to use the GMP backend with Boost Multiprecision Library.

As I showed in a different question, I already have working code that relies only on Boost Multiprecision Library. What I'm trying to do is to use GMP's high precision floats instead of the ones that come with Boost. Like the following:

#include <iostream>
#include <boost/math/distributions/negative_binomial.hpp>
#include <boost/multiprecision/gmp.hpp>

using namespace std;
using namespace boost;

typedef boost::multiprecision::number<boost::multiprecision::gmp_float<50>> myPrecision;
// typedef boost::multiprecision::mpf_float_50 myPrecision; // this also raises the errors

template <class T1, class T2>
myPrecision negbinPDF(T1 passed_val, T2 passed_par1, T2 passed_par2)
{
    myPrecision val = myPrecision(passed_val);
    myPrecision par1 =  myPrecision(passed_par1);
    myPrecision par2 = myPrecision(passed_par2);

    return math::pdf(math::negative_binomial_distribution<myPrecision>(par1, par2), val);
};

int main() {
    auto p = negbinPDF(1.23456789012345678901234567890, 8.0, 0.25);
    cout << "The PDF is: " << p << endl;
}

When running the above code, many errors are raised (see here), starting with some undefined references. Hence my question: How can I link to GMP using Visual Studio Code's Code Runner (in Linux)?

728x90

0 Answers How to link to GMP using C++ in Visual Studio Code's Code Runner (in Linux)?