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