From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Banel Subject: Re: ob-C doesn't support load libraries Date: Fri, 10 Jun 2016 18:44:01 +0200 Message-ID: <575AEE51.1060704@free.fr> References: Mime-Version: 1.0 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42673) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBPXT-0000jy-OP for emacs-orgmode@gnu.org; Fri, 10 Jun 2016 12:44:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bBPXQ-0003bU-Bt for emacs-orgmode@gnu.org; Fri, 10 Jun 2016 12:44:07 -0400 Received: from smtp2-g21.free.fr ([212.27.42.2]:37750) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBPXP-0003bL-Tx for emacs-orgmode@gnu.org; Fri, 10 Jun 2016 12:44:04 -0400 Received: from [IPv6:2a01:e35:2e21:def0:dc9c:294f:f01c:18ba] (unknown [IPv6:2a01:e35:2e21:def0:dc9c:294f:f01c:18ba]) by smtp2-g21.free.fr (Postfix) with ESMTP id 452ED200327 for ; Fri, 10 Jun 2016 16:35:51 +0200 (CEST) In-Reply-To: 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" To: emacs-orgmode@gnu.org
Change the first line to

=C2=A0 #+BEGIN_SRC C :libs -lm

This instructs the C++ compiler to link with the "m" library (mathematical functions).

You need a pretty new version of ob-C.el, as the :libs parameter was introduced recently.


Le 10/06/2016 14:01, numbchild@gmail.com a =C3=A9crit=C2=A0:
I have a code example like this:

#+BEGIN_SRC C
#include <stdio.h>
#include <math.h>

/* define complex struct */
struct complex_struct {
=C2=A0 double x, y;
};

/* some helper functions on complex struct */
double real_part(struct complex_struct z) {
=C2=A0 return z.x;
}
double img_part(struct complex_struct z) {
=C2=A0 return z.y;
}
double magnitude(struct complex_struct z) {
=C2=A0 return sqrt(z.x * z.x + z.y * z.y);
}
double angle(struct complex_struct z) {<= /div>
=C2=A0 return atan2(z.y, z.x);
}

/* helper functions to construct complex variable */
struct complex_struct make_from_real_img(double x, double y) {
=C2=A0 struct complex_struct z;
=C2=A0 z.x =3D x;
=C2=A0 z.y =3D y;
=C2=A0 return z;
}

struct complex_struct make_from_mag_ang(double r, double A) {
=C2=A0 struct complex_struct z;
=C2=A0 z.x =3D r * cos(A);
=C2=A0 z.y =3D r * sin(A);
=C2=A0 return z;
}

/* implement complex arithemtic */
struct complex_struct add_complex(struct complex_struct z1, struct complex_struct z2) {
=C2=A0 return make_from_real_img(real_part(z1) = + real_part(z2), img_part(z1) + img_part(z2));
}

int main(int argc, char *argv[]) {
=C2=A0 struct complex_struct z1, z2 =3D {1.1, 2= .4};
=C2=A0=C2=A0
=C2=A0 struct complex_struct z;
=C2=A0 z =3D add_complex(z1, z2);
=C2=A0=C2=A0
=C2=A0 printf("%f", z);
=C2=A0 return 0;
}
#+END_SRC

But evaluate it got error:

```
/tmp/cckFlXlJ.o: In function `magnitude':
C-src-18467gDZ.c:(.text+0xa8): undefined reference to `sqrt'
/tmp/cckFlXlJ.o: In function `angle':
C-src-18467gDZ.c:(.text+0xfe): undefined reference to `atan2'
/tmp/cckFlXlJ.o: In function `make_from_mag_ang':
C-src-18467gDZ.c:(.text+0x174): undefined reference to `cos'
C-src-18467gDZ.c:(.text+0x190): undefined reference to `sin'
collect2: error: ld returned 1 exit status
zsh:1: no such file or directory: /tmp/babel-18467-Yn/C-bin-18467tNf
```

So I think `ob-C.el` doesn't support to load included header files.

[stardiviner]=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 <Hack this world!>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 GPG key ID: 47= C32433
IRC(freeenode): stardiviner =C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 Twitter:=C2=A0 @numbchild
Key fingerprint =3D 9BAA 92BC CDDD B9EF 3B36=C2=A0 CB99= B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/