emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-babel C math.h issue
@ 2016-03-06 22:44 Oz Ben-Ami
  2016-03-10  9:43 ` Nicolas Goaziou
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Oz Ben-Ami @ 2016-03-06 22:44 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 884 bytes --]

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.

Oz

[-- Attachment #1.2: Type: text/html, Size: 1049 bytes --]

[-- Attachment #2: testC.org --]
[-- Type: application/octet-stream, Size: 267 bytes --]

#+BEGIN_SRC elisp
(custom-set-variables
 '(org-babel-load-languages
   (quote
    ((emacs-lisp . t)
     (C . t)))))
#+END_SRC

#+RESULTS:


#+BEGIN_SRC C :includes '(<math.h> <stdio.h>) :flags -lm
int i=9;
printf("%d\n",(int)sqrt(pow(i,i)));
#+END_SRC

#+RESULTS:



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

end of thread, other threads:[~2016-03-26 17:09 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).