From: Nick Dokos <ndokos@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: org-babel C math.h issue
Date: Thu, 10 Mar 2016 16:19:54 -0500 [thread overview]
Message-ID: <87d1r21151.fsf@alphaville.usersys.redhat.com> (raw)
In-Reply-To: CABYMxKzMm2iRFGZ3AMKno6UjfyQz_CBTmc4e4yZKgShhcW0kqQ@mail.gmail.com
Oz Ben-Ami <ozzieba@gmail.com> writes:
> Hi,
>
> I'm a new org user, and I'm sorry if I'm missing something obvious. When executing a C code snippet with
> org-babel, that contains a math function, I get the famous "undefined reference" errors. I tried adding
> ":flags -lm", but that doesn't help. Looking at the code, it seems the -lm flag is inserted in the wrong
> place, before the source file. An easy change would be in line 147 of ob-C.el version 8.3.4-634, moving
> "flags" to after the source file. This seems to work, but I don't know if it would break anything else.
>
> A minimal working example, attached, includes the following snippet:
>
> #+BEGIN_SRC C :includes '(<math.h> <stdio.h>) :flags -lm
> int i=9;
> printf("%d\n",(int)sqrt(i));
> #+END_SRC
>
> Note the issue disappears if constants are directly used rather than variables, presumably because the
> function call is optimized away entirely.
>
> Any thoughts are appreciated.
>
I can't reproduce it either (with fairly recent emacs and bleeding-edge
org-mode, but the code in question has not changed since 8.2.7 or so).
The command that is executed looks like this:
gcc -o /tmp/babel-212464kj/C-bin-21246R6L -lm /tmp/babel-212464kj/C-src-21246EwF.c
and that should work fine for gcc: you don't need to have the -lm after the
source file.
You can test that that's the case: put your program into a file, say foo.c, and
execute
gcc -o foo.out -lm foo.c
Does that give you undefined references?
--
Nick
next prev parent reply other threads:[~2016-03-10 21:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-06 22:44 org-babel C math.h issue Oz Ben-Ami
2016-03-10 9:43 ` Nicolas Goaziou
2016-03-10 14:06 ` Anssi Saari
2016-03-10 15:20 ` John Kitchin
2016-03-10 21:19 ` Nick Dokos [this message]
2016-03-11 6:44 ` Anssi Saari
2016-03-11 15:36 ` Nick Dokos
2016-03-11 18:52 ` Thierry Banel
2016-03-11 19:14 ` Oz Ben-Ami
2016-03-11 23:14 ` Thierry Banel
2016-03-20 14:03 ` [PATCH] " Thierry Banel
2016-03-25 23:42 ` Nicolas Goaziou
2016-03-26 17:08 ` Thierry Banel
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87d1r21151.fsf@alphaville.usersys.redhat.com \
--to=ndokos@gmail.com \
--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 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.