You may try:
#+header: :includes '("<iostream>" "<ginac.h>")

Also, you have this commented line:
# #+header: :var table=
It seems to break the #+header: chain
Just remove it.

By the way, to figure out future compilation problems, you may click on the error:
/tmp/babel-eqG2i0/C-src-3zG2ec.cpp:16:1: error: unknown type name 'ex'
This will open the source file actually being compiled.

Have fun!



Le 26/09/2022 à 21:13, Roger Mason a écrit :
Hello,

I wish to compile & run this source block in org-mode:

#+name: gnc_cav
#+header: :includes  <iostream> <ginac.h>
#+header: :libs -L/usr/local/lib -lginac -lcln
#+header: :flags -std=c++17
#+header: :namespaces std GiNaC
# #+header: :var table=
#+header: :var job="vectors" :var vol=113.13115406160385926 :var r=1.0995524816924328312
#+header: :var a=4.916 :var c=5.4054
#+header: :main no
#+begin_src  C++
    ex vol(symbol a, symbol c)
    {
      ex v = a*a * c * sin(60*Pi/180);

      return v;
    }

    ex coa(symbol a, symbol c) {
      ex covera = c/a;

      return covera;
    }

    ex scl(symbol a, symbol c, double ad, double cd) {

      //  symbol v("v");
      // symbol r("r");
      ex v = vol(a,c);

      ex r = coa(a,c);
      numeric three(3);

      //  ex s = power(v.subs(lst{a==ad,c==cd})),1/three)/(power(sin(60*Pi/180),1/three) * power(r.subs(lst{a==ad,c==cd}),1/three));
      ex s = power(v.subs(lst{a==ad,c==cd}),1/three)/(power(sin(60*Pi/180),1/three) * power(r.subs(lst{a==ad,c==cd}),1/three));

      return s;
    }

    ex scl(double vd, double rd) {

      numeric three(3);

      ex s = power(vd,1/three)/(power(sin(60*Pi/180),1/three) * power(rd,1/three));

      return s;
    }

    int main () {
      if ( strncmp(job, "volume", 6) == 0) { // ./v volume a c, calculate volume

	symbol as("as");
	symbol cs("cs");

	ex v = vol(as, cs);
	cout << "Volume = " << v.subs(lst{as == a, cs == c}).evalf() << "\n";

	ex r = coa(as, cs);
	cout << "c/a = " << r.subs(lst{as == a, cs == c}).evalf() << "\n";

	ex a_calc = scl(as, cs, a, c);
	cout << "a_calc = " << a_calc.evalf() << "\n";
	cout << "c_calc = "
	     << a_calc.evalf() * r.subs(lst{as == a, cs == c}).evalf() << "\n";

      } else if ( job,"vectors",5) == 0 ) { // ./v vectors vol c/a

	//double vd = stod(argv[2]);
	//double rd = stod(argv[3]);
	ex a_calc = scl(v,r);
	cout << "a_calc = " << a_calc.evalf() << "\n";
	cout << "c_calc = " << a_calc.evalf() * rd << "\n";

	//double a_scale = a;
      } // vectors
    } // main

#+end_src

When I attempt compilation using 'C-c C-c' I get:

/tmp/babel-eqG2i0/C-src-3zG2ec.cpp:16:1: error: unknown type name 'ex'
ex vol(symbol a, symbol c)

and lots of similar errors.  I infer this is because ginac.h is not
found.  I have tried specifying <ginac/ginac.h> in ':includes' to no
avail.  I have tried specifying the full path to ginac.h:
</usr/local/lib/ginac/ginac.h> and specifying -I/usr/local/lib/ginac/ as
part of ':includes', but the error persists.

Maybe the C++ support is not set up to handle this use case, but perhaps
I am missing something.

Any help will be much appreciated.

Thanks,
Roger


Reply via email to