From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: org-babel C math.h issue Date: Thu, 10 Mar 2016 16:19:54 -0500 Message-ID: <87d1r21151.fsf@alphaville.usersys.redhat.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46508) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ae808-0007VM-BD for emacs-orgmode@gnu.org; Thu, 10 Mar 2016 16:20:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ae805-0004j8-5A for emacs-orgmode@gnu.org; Thu, 10 Mar 2016 16:20:08 -0500 Received: from plane.gmane.org ([80.91.229.3]:45213) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ae804-0004ib-VW for emacs-orgmode@gnu.org; Thu, 10 Mar 2016 16:20:05 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ae801-0003ui-Jx for emacs-orgmode@gnu.org; Thu, 10 Mar 2016 22:20:01 +0100 Received: from nat-pool-bos-t.redhat.com ([66.187.233.206]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 10 Mar 2016 22:20:01 +0100 Received: from ndokos by nat-pool-bos-t.redhat.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 10 Mar 2016 22:20:01 +0100 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 Oz Ben-Ami 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 '( ) :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