emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Roger Mason <rmason@mun.ca>
To: orgmode <emacs-orgmode@gnu.org>
Subject: Compiling a C++ source block
Date: Mon, 26 Sep 2022 16:43:55 -0230	[thread overview]
Message-ID: <y657d1q3pdb.fsf@mun.ca> (raw)

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	other threads:[~2022-09-26 19:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-26 19:13 Roger Mason [this message]
2022-09-26 19:56 ` Compiling a C++ source block 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=y657d1q3pdb.fsf@mun.ca \
    --to=rmason@mun.ca \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).