From mboxrd@z Thu Jan 1 00:00:00 1970 From: "numbchild@gmail.com" Subject: Re: ob-C doesn't support load libraries Date: Mon, 13 Jun 2016 08:23:29 +0800 Message-ID: References: <575AEE51.1060704@free.fr> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a113d46ae8beeec05351de702 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45249) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCFfh-0007t7-S3 for emacs-orgmode@gnu.org; Sun, 12 Jun 2016 20:24:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCFfb-0008SM-Bx for emacs-orgmode@gnu.org; Sun, 12 Jun 2016 20:24:05 -0400 Received: from mail-yw0-x22c.google.com ([2607:f8b0:4002:c05::22c]:34476) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCFfb-0008Ry-5u for emacs-orgmode@gnu.org; Sun, 12 Jun 2016 20:23:59 -0400 Received: by mail-yw0-x22c.google.com with SMTP id c72so112760902ywb.1 for ; Sun, 12 Jun 2016 17:23:58 -0700 (PDT) In-Reply-To: <575AEE51.1060704@free.fr> 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: Thierry Banel Cc: Org-mode --001a113d46ae8beeec05351de702 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thanks. [stardiviner] GPG key ID: 47C32433 IRC(freeenode): stardiviner Twitter: @numbchild Key fingerprint =3D 9BAA 92BC CDDD B9EF 3B36 CB99 B8C4 B8E5 47C3 2433 Blog: http://stardiviner.github.io/ On Sat, Jun 11, 2016 at 12:44 AM, Thierry Banel wrote: > Change the first line to > > #+BEGIN_SRC C *:libs -lm* > > This instructs the C++ compiler to link with the "m" library (mathematica= l > 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 : > > I have a code example like this: > > #+BEGIN_SRC C > #include > #include > > /* define complex struct */ > struct complex_struct { > double x, y; > }; > > /* some helper functions on complex struct */ > double real_part(struct complex_struct z) { > return z.x; > } > double img_part(struct complex_struct z) { > return z.y; > } > double magnitude(struct complex_struct z) { > return sqrt(z.x * z.x + z.y * z.y); > } > double angle(struct complex_struct z) { > return atan2(z.y, z.x); > } > > /* helper functions to construct complex variable */ > struct complex_struct make_from_real_img(double x, double y) { > struct complex_struct z; > z.x =3D x; > z.y =3D y; > return z; > } > > struct complex_struct make_from_mag_ang(double r, double A) { > struct complex_struct z; > z.x =3D r * cos(A); > z.y =3D r * sin(A); > return z; > } > > /* implement complex arithemtic */ > struct complex_struct add_complex(struct complex_struct z1, struct > complex_struct z2) { > return make_from_real_img(real_part(z1) + real_part(z2), img_part(z1) + > img_part(z2)); > } > > int main(int argc, char *argv[]) { > struct complex_struct z1, z2 =3D {1.1, 2.4}; > > struct complex_struct z; > z =3D add_complex(z1, z2); > > printf("%f", z); > 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] GPG key ID: 47C32433 > IRC(freeenode): stardiviner Twitter: @numbchild > Key fingerprint =3D 9BAA 92BC CDDD B9EF 3B36 CB99 B8C4 B8E5 47C3 2433 > Blog: http://stardiviner.github.io/ > > > --001a113d46ae8beeec05351de702 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Thanks.

[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: 47C32433
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 fi= ngerprint =3D 9BAA 92BC CDDD B9EF 3B36=C2=A0 CB99 B8C4 B8E5 47C3 2433
Bl= og: http://star= diviner.github.io/

On Sat, Jun 11, 2016 at 12:44 AM, Thierry Ba= nel <tbanelwebmin@free.fr> wrote:
=20 =20 =20
Change the first line to

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

This instructs the C++ compiler to link with the "m" librar= y (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) {
=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:

```<= /div>
/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: 47C3= 2433
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 B= 8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/


--001a113d46ae8beeec05351de702--