[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] org-babel C math.h issue
From: |
Nick Dokos |
Subject: |
Re: [O] org-babel C math.h issue |
Date: |
Thu, 10 Mar 2016 16:19:54 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
Oz Ben-Ami <address@hidden> 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