From mboxrd@z Thu Jan 1 00:00:00 1970 From: "numbchild@gmail.com" Subject: ob-C doesn't support load libraries Date: Fri, 10 Jun 2016 20:01:03 +0800 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a114d71d8be06920534eb4c2f Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBL84-0006eU-Eo for emacs-orgmode@gnu.org; Fri, 10 Jun 2016 08:01:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bBL81-0001eb-Vu for emacs-orgmode@gnu.org; Fri, 10 Jun 2016 08:01:35 -0400 Received: from mail-yw0-x230.google.com ([2607:f8b0:4002:c05::230]:34009) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBL81-0001eQ-Qa for emacs-orgmode@gnu.org; Fri, 10 Jun 2016 08:01:33 -0400 Received: by mail-yw0-x230.google.com with SMTP id c72so63999913ywb.1 for ; Fri, 10 Jun 2016 05:01:33 -0700 (PDT) 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: Org-mode --001a114d71d8be06920534eb4c2f Content-Type: text/plain; charset=UTF-8 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 = x; z.y = y; return z; } struct complex_struct make_from_mag_ang(double r, double A) { struct complex_struct z; z.x = r * cos(A); z.y = 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 = {1.1, 2.4}; struct complex_struct z; z = 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 = 9BAA 92BC CDDD B9EF 3B36 CB99 B8C4 B8E5 47C3 2433 Blog: http://stardiviner.github.io/ --001a114d71d8be06920534eb4c2f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I have a code example like this:
=
#+BEGIN_SRC C
#include <stdio.h&g= t;
#include <math.h>
<= font face=3D"trebuchet ms, sans-serif">
/* define complex struct = */
struct complex_struct {
<= font face=3D"trebuchet ms, sans-serif">=C2=A0 double x, y;
};<= /div>
<= br>
/* some helper functions on complex struct */
double real_p= art(struct complex_struct z) {
=C2=A0 return z.x;
}
doubl= e img_part(struct complex_struct z) {
=C2=A0 return z.y;
=
}
=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 func= tions to construct complex variable */
struct complex_struct make_fro= m_real_img(double x, double y) {
<= font face=3D"trebuchet ms, sans-serif">=C2=A0 struct complex_struct z;
=C2=A0 z.y =3D y;
=C2=A0 return z;
}<= /font>

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);<= /font>
=C2=A0 z.y =3D r * sin(A);
<= font face=3D"trebuchet ms, sans-serif">=C2=A0 return z;
}

<= /font>
/* implement complex arithemtic */
struct complex_struct add_co= mplex(struct complex_struct z1, struct complex_struct z2) {
=C2=A0 re= turn make_from_real_img(real_part(z1) + real_part(z2), img_part(z1) + img_p= art(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);<= /font>
=C2=A0=C2=A0
=C2=A0 printf("%f", z);
=C2=A0 ret= urn 0;
}
#+END_SRC

But evaluate it got error:

```
/tmp/cckFlXlJ.o: In function `magnit= ude':
C-src-18467gDZ.c:(.text+0xa8): undefined reference to `= sqrt'
/tmp/cckFlXlJ.o: In function `angle':
C-s= rc-18467gDZ.c:(.text+0xfe): undefined reference to `atan2'
/t= mp/cckFlXlJ.o: In function `make_from_mag_ang':
C-src-18467gD= Z.c:(.text+0x174): undefined reference to `cos'
C-src-18467gD= Z.c:(.text+0x190): undefined reference to `sin'
collect2: err= or: 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.
=

[stardiv= iner]=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(f= reeenode): 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/
<= /div>
--001a114d71d8be06920534eb4c2f--