]> www.ginac.de Git - ginac.git/blob - doc/examples/compile3.cpp
don't mention CVS any more, describe how to install from git.
[ginac.git] / doc / examples / compile3.cpp
1 #include <ctime>
2 #include <iostream>
3 using namespace std;
4 #include <ginac/ginac.h>
5 using namespace GiNaC;
6
7 /*
8  * Demonstrates the use of link_ex.
9  *
10  * When run for the first time link_ex will fail. This is a rude way of
11  * checking whether the needed .so file is available.  The .so is then created
12  * by compile_ex using the filename parameter. When run again link_ex will use
13  * the existing .so file.
14  *
15  */
16 int main()
17 {
18         FUNCP_2P fp;
19         try {
20                 link_ex("compile3_testprg.so", fp);
21                 cout << "Using existing 'compile3_testprg.so'." << endl;
22         }
23         catch (const std::exception& e) {
24                 // hope the exception is just raised because of missing 'compile2_testprg.so' file,
25                 // so being lazy no error management here ...
26                 cout << "Error: " << e.what() << endl;
27                 cout << "Building new 'compile3_testprg.so'." << endl;
28                 symbol a, b;
29                 ex expr = a*b;
30                 compile_ex(expr, a, b, fp, "compile3_testprg");
31         }
32
33         cout << "result of 2.3*1.5 is " << fp(2.3, 1.5) << endl;
34
35         return 0;
36 }