all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Compiling a C++ source block
@ 2022-09-26 19:13 Roger Mason
  2022-09-26 19:56 ` tbanelwebmin
  0 siblings, 1 reply; 6+ messages in thread
From: Roger Mason @ 2022-09-26 19:13 UTC (permalink / raw)
  To: orgmode

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-11-25  7:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-26 19:13 Compiling a C++ source block Roger Mason
2022-09-26 19:56 ` tbanelwebmin
2022-09-27  8:26   ` Roger Mason
2022-09-29  2:25   ` Ihor Radchenko
2022-09-29 20:03     ` tbanelwebmin
2022-11-25  7:45       ` Ihor Radchenko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.