From mboxrd@z Thu Jan 1 00:00:00 1970 From: Oz Ben-Ami Subject: org-babel C math.h issue Date: Sun, 6 Mar 2016 17:44:26 -0500 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=001a1136c66ae93aec052d691891 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:39116) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1achQ3-0000Nf-75 for emacs-orgmode@gnu.org; Sun, 06 Mar 2016 17:45:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1achQ2-0000og-6w for emacs-orgmode@gnu.org; Sun, 06 Mar 2016 17:44:59 -0500 Received: from mail-pa0-x235.google.com ([2607:f8b0:400e:c03::235]:35149) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1achQ1-0000oa-Ux for emacs-orgmode@gnu.org; Sun, 06 Mar 2016 17:44:58 -0500 Received: by mail-pa0-x235.google.com with SMTP id bj10so67200280pad.2 for ; Sun, 06 Mar 2016 14:44:57 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --001a1136c66ae93aec052d691891 Content-Type: multipart/alternative; boundary=001a1136c66ae93ae8052d69188f --001a1136c66ae93ae8052d69188f Content-Type: text/plain; charset=UTF-8 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 '( ) :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 --001a1136c66ae93ae8052d69188f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
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 doe= sn't help. Looking at the code, it seems the -lm flag is inserted in th= e 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 e= lse.

A minimal working example, attached, includes the following sni= ppet:

#+BEGIN_SRC C :includes '(<math.h> <stdio.h>) = :flags -lm
int i=3D9;
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 ent= irely.

Any thoughts are appreciated.

Oz
--001a1136c66ae93ae8052d69188f-- --001a1136c66ae93aec052d691891 Content-Type: application/octet-stream; name="testC.org" Content-Disposition: attachment; filename="testC.org" Content-Transfer-Encoding: base64 X-Attachment-Id: f_ilh5b71u0 IytCRUdJTl9TUkMgZWxpc3AKKGN1c3RvbS1zZXQtdmFyaWFibGVzCiAnKG9yZy1iYWJlbC1sb2Fk LWxhbmd1YWdlcwogICAocXVvdGUKICAgICgoZW1hY3MtbGlzcCAuIHQpCiAgICAgKEMgLiB0KSkp KSkKIytFTkRfU1JDCgojK1JFU1VMVFM6CgoKIytCRUdJTl9TUkMgQyA6aW5jbHVkZXMgJyg8bWF0 aC5oPiA8c3RkaW8uaD4pIDpmbGFncyAtbG0KaW50IGk9OTsKcHJpbnRmKCIlZFxuIiwoaW50KXNx cnQocG93KGksaSkpKTsKIytFTkRfU1JDCgojK1JFU1VMVFM6CgoK --001a1136c66ae93aec052d691891--