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