1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <ctime>
#include <iostream>
#ifdef IN_GINAC
#include "ginac.h"
#else
#include <ginac/ginac.h>
#endif
using namespace std;
using namespace GiNaC;
/*
* Demonstrates the use of link_ex.
*
* When run for the first time link_ex will fail. This is a rude way of
* checking whether the needed .so file is available. The .so is then created
* by compile_ex using the filename parameter. When run again link_ex will use
* the existing .so file.
*
*/
int main()
{
FUNCP_2P fp;
try {
link_ex("compile3_testprg.so", fp);
cout << "Using existing 'compile3_testprg.so'." << endl;
}
catch (const std::exception& e) {
// hope the exception is just raised because of missing 'compile2_testprg.so' file,
// so being lazy no error management here ...
cout << "Error: " << e.what() << endl;
cout << "Building new 'compile3_testprg.so'." << endl;
symbol a, b;
ex expr = a*b;
// Optionally, compile with custom compiler flags:
// setenv("CXXFLAGS", "-O3 -fomit-frame-pointer -ffast-math", 1);
compile_ex(expr, a, b, fp, "compile3_testprg");
}
cout << "result of 2.3*1.5 is " << fp(2.3, 1.5) << endl;
return 0;
}
|